github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/plugins/mqtt_bridge/types.go (about)

     1  // This file is part of the Smart Home
     2  // Program complex distribution https://github.com/e154/smart-home
     3  // Copyright (C) 2016-2023, Filippov Alex
     4  //
     5  // This library is free software: you can redistribute it and/or
     6  // modify it under the terms of the GNU Lesser General Public
     7  // License as published by the Free Software Foundation; either
     8  // version 3 of the License, or (at your option) any later version.
     9  //
    10  // This library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13  // Library General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Lesser General Public
    16  // License along with this library.  If not, see
    17  // <https://www.gnu.org/licenses/>.
    18  
    19  package mqtt_bridge
    20  
    21  import (
    22  	"github.com/e154/smart-home/common"
    23  	m "github.com/e154/smart-home/models"
    24  	"github.com/e154/smart-home/system/supervisor"
    25  )
    26  
    27  const (
    28  	// Name ...
    29  	Name = "mqtt_bridge"
    30  	// FuncEntityAction ...
    31  	FuncEntityAction = "entityAction"
    32  
    33  	Version = "0.0.1"
    34  )
    35  
    36  type Direction string
    37  
    38  const (
    39  	DirectionIn   = Direction("in")
    40  	DirectionOut  = Direction("out")
    41  	DirectionBoth = Direction("both")
    42  )
    43  
    44  const (
    45  	AttrConnected = "connected"
    46  	AttrOffline   = "offline"
    47  
    48  	AttrKeepAlive      = "keepAlive"
    49  	AttrPingTimeout    = "pingTimeout"
    50  	AttrBroker         = "broker"
    51  	AttrClientID       = "clientID"
    52  	AttrConnectTimeout = "connectTimeout"
    53  	AttrCleanSession   = "cleanSession"
    54  	AttrUsername       = "username"
    55  	AttrPassword       = "password"
    56  	AttrQos            = "qos"
    57  	AttrDirection      = "direction"
    58  	AttrTopics         = "topics"
    59  )
    60  
    61  // NewSettings ...
    62  func NewSettings() m.Attributes {
    63  	return m.Attributes{
    64  		AttrKeepAlive: {
    65  			Name:  AttrKeepAlive,
    66  			Type:  common.AttributeInt,
    67  			Value: 15,
    68  		},
    69  		AttrPingTimeout: {
    70  			Name:  AttrPingTimeout,
    71  			Type:  common.AttributeInt,
    72  			Value: 10,
    73  		},
    74  		AttrBroker: {
    75  			Name:  AttrBroker,
    76  			Type:  common.AttributeString,
    77  			Value: "tcp://server:port",
    78  		},
    79  		AttrClientID: {
    80  			Name: AttrClientID,
    81  			Type: common.AttributeString,
    82  		},
    83  		AttrConnectTimeout: {
    84  			Name:  AttrConnectTimeout,
    85  			Type:  common.AttributeInt,
    86  			Value: 30,
    87  		},
    88  		AttrCleanSession: {
    89  			Name:  AttrCleanSession,
    90  			Type:  common.AttributeBool,
    91  			Value: false,
    92  		},
    93  		AttrUsername: {
    94  			Name: AttrUsername,
    95  			Type: common.AttributeString,
    96  		},
    97  		AttrPassword: {
    98  			Name: AttrPassword,
    99  			Type: common.AttributeEncrypted,
   100  		},
   101  		AttrQos: {
   102  			Name:  AttrQos,
   103  			Type:  common.AttributeInt,
   104  			Value: 0,
   105  		},
   106  		AttrDirection: {
   107  			Name:  AttrDirection,
   108  			Type:  common.AttributeString,
   109  			Value: DirectionIn,
   110  		},
   111  		AttrTopics: {
   112  			Name:  AttrTopics,
   113  			Type:  common.AttributeString,
   114  			Value: "owntracks/#",
   115  		},
   116  	}
   117  }
   118  
   119  // NewStates ...
   120  func NewStates() (states map[string]supervisor.ActorState) {
   121  
   122  	states = map[string]supervisor.ActorState{
   123  		AttrConnected: {
   124  			Name:        AttrConnected,
   125  			Description: "connected",
   126  		},
   127  		AttrOffline: {
   128  			Name:        AttrOffline,
   129  			Description: "offline",
   130  		},
   131  	}
   132  
   133  	return
   134  }