github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/system/zigbee2mqtt/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 zigbee2mqtt
    20  
    21  import (
    22  	"context"
    23  	"time"
    24  
    25  	m "github.com/e154/smart-home/models"
    26  )
    27  
    28  // Zigbee2mqtt ...
    29  type Zigbee2mqtt interface {
    30  	Start(ctx context.Context) error
    31  	Shutdown(ctx context.Context) error
    32  	GetBridgeInfo(id int64) (*m.Zigbee2mqttInfo, error)
    33  	ResetBridge(bridgeId int64) (err error)
    34  	BridgeDeviceBan(bridgeId int64, friendlyName string) (err error)
    35  	BridgeDeviceWhitelist(bridgeId int64, friendlyName string) (err error)
    36  	BridgeNetworkmap(bridgeId int64) (networkmap string, err error)
    37  	BridgeUpdateNetworkmap(bridgeId int64) (err error)
    38  	GetTopicByDevice(model *m.Zigbee2mqttDevice) (topic string, err error)
    39  	DeviceRename(friendlyName, name string) (err error)
    40  }
    41  
    42  // Zigbee2mqttBridge ...
    43  type Zigbee2mqttBridge struct {
    44  	m.Zigbee2mqtt
    45  	ScanInProcess bool       `json:"scan_in_process"`
    46  	LastScan      *time.Time `json:"last_scan"`
    47  	Networkmap    string     `json:"networkmap"`
    48  	Status        string     `json:"status"`
    49  }
    50  
    51  // BridgeLog ...
    52  type BridgeLog struct {
    53  	Type    string                 `json:"type"`
    54  	Message string                 `json:"message"`
    55  	Meta    map[string]interface{} `json:"meta"`
    56  }
    57  
    58  // BridgeConfigMeta ...
    59  type BridgeConfigMeta struct {
    60  	Transportrev int64 `json:"transportrev"`
    61  	Product      int64 `json:"product"`
    62  	Majorrel     int64 `json:"majorrel"`
    63  	Minorrel     int64 `json:"minorrel"`
    64  	Maintrel     int64 `json:"maintrel"`
    65  	Revision     int64 `json:"revision"`
    66  }
    67  
    68  // BridgeConfigCoordinator ...
    69  type BridgeConfigCoordinator struct {
    70  	Type string           `json:"type"`
    71  	Meta BridgeConfigMeta `json:"meta"`
    72  }
    73  
    74  // BridgeConfig ...
    75  type BridgeConfig struct {
    76  	Version     string                  `json:"version"`
    77  	Commit      string                  `json:"commit"`
    78  	Coordinator BridgeConfigCoordinator `json:"coordinator"`
    79  	LogLevel    string                  `json:"log_level"`
    80  	PermitJoin  string                  `json:"permit_join"`
    81  }
    82  
    83  const (
    84  	active  = "active"
    85  	banned  = "banned"
    86  	removed = "removed"
    87  )
    88  
    89  const (
    90  	// EventDeviceAnnounce ...
    91  	EventDeviceAnnounce = "device_announce"
    92  	// EventDeviceLeave ...
    93  	EventDeviceLeave = "device_leave"
    94  	// EventDeviceJoined ...
    95  	EventDeviceJoined = "device_joined"
    96  	// EventDeviceInterview ...
    97  	EventDeviceInterview = "device_interview"
    98  )
    99  
   100  const (
   101  	// StatusStarted ...
   102  	StatusStarted = "started"
   103  	// StatusFailed ...
   104  	StatusFailed = "failed"
   105  )
   106  
   107  // EventDeviceInfoDefExpose ...
   108  type EventDeviceInfoDefExpose struct {
   109  	Access      int64                      `json:"access,omitempty"`
   110  	Description string                     `json:"description,omitempty"`
   111  	Name        string                     `json:"name,omitempty"`
   112  	Property    string                     `json:"property,omitempty"`
   113  	Type        string                     `json:"type,omitempty"`
   114  	Unit        string                     `json:"unit,omitempty"`
   115  	ValueMax    int64                      `json:"value_max,omitempty"`
   116  	ValueMin    int64                      `json:"value_min,omitempty"`
   117  	Values      []string                   `json:"values,omitempty"`
   118  	Features    []EventDeviceInfoDefExpose `json:"features,omitempty"`
   119  }
   120  
   121  // EventDeviceInfoDef ...
   122  type EventDeviceInfoDef struct {
   123  	Description string                     `json:"description,omitempty"`
   124  	Exposes     []EventDeviceInfoDefExpose `json:"exposes"`
   125  	Model       string                     `json:"model"`
   126  	Options     []string                   `json:"options"`
   127  	SupportsOta bool                       `json:"supports_ota"`
   128  	Vendor      string                     `json:"vendor"`
   129  }
   130  
   131  const (
   132  	// Coordinator ...
   133  	Coordinator = "Coordinator"
   134  	// EndDevice ...
   135  	EndDevice = "EndDevice"
   136  )
   137  
   138  // DeviceInfo ...
   139  type DeviceInfo struct {
   140  	Definition         EventDeviceInfoDef `json:"definition"`
   141  	FriendlyName       string             `json:"friendly_name"`
   142  	IeeeAddress        string             `json:"ieee_address"`
   143  	Status             string             `json:"status,omitempty"`
   144  	InterviewCompleted bool               `json:"interview_completed,omitempty"`
   145  	Interviewing       bool               `json:"interviewing,omitempty"`
   146  	ModelId            string             `json:"model_id,omitempty"`
   147  	NetworkAddress     int64              `json:"network_address,omitempty"`
   148  	PowerSource        string             `json:"power_source,omitempty"`
   149  	Supported          bool               `json:"supported,omitempty"`
   150  	Type               string             `json:"type,omitempty"`
   151  }
   152  
   153  // Event ...
   154  type Event struct {
   155  	Data DeviceInfo `json:"data"`
   156  	Type string     `json:"type"`
   157  }