import json, tables, options type ActionType* = enum SwitchStateAction, SetBrightnessAction, SetColorXYAction, SetColorTemperatureAction, GetClientConfigAction, SetSubscriptionStateAction type Action* = object accessToken*: Option[string] deviceName*: string case type*: ActionType of SwitchStateAction: relay*: Option[uint8] state*: Option[bool] toggle*: Option[bool] of SetBrightnessAction: brightness*: uint8 of SetColorXYAction: colorX*: float colorY*: float of SetColorTemperatureAction: colorTemperature*: int of GetClientConfigAction: configName*: string of SetSubscriptionStateAction: subscribed*: bool type DeviceType* = enum PowerMeter, RelayBoard, LacrosseTempSensor, Zigbee2MqttLamp, Zigbee2MqttRelay, Zigbee2MqttRemote, Zigbee2MqttMotionSensor type Zigbee2MqttLampType* = enum RGB, WhiteSpectrum Switchable type DeviceState* = object lastUpdated*: Option[int64] case type*: DeviceType of PowerMeter: power*: float32 cosphi*: float32 voltage*: float32 `import`*: float32 frequency*: float32 of RelayBoard: relays*: seq[bool] of LacrosseTempSensor: humidity*: float32 temperature*: float32 weakBattery*: bool of Zigbee2MqttLamp: lampType*: Zigbee2MqttLampType lampState*: bool lampBrightness*: int lampColorX*: float lampColorY*: float lampColorTemperature*: int lampLinkquality*: int of Zigbee2MqttRelay: relayState*: bool relayLinkquality*: int else: unusedValue: Option[bool] type DeviceConfig* = object address*: Option[uint8] deviceName*: Option[string] case type*: DeviceType of PowerMeter: model*: string of RelayBoard: firstRegister*: uint8 count*: uint8 of LacrosseTempSensor: id*: string of Zigbee2MqttLamp: lampType*: Zigbee2MqttLampType of Zigbee2MqttRemote: actions*: Table[string, seq[Action]] of Zigbee2MqttMotionSensor: occupyActions*: seq[Action] clearActions*: seq[Action] else: unusedValue: Option[bool] type ModbusConfig* = object host*: string port*: uint16 type MqttConfig* = object host*: string port*: int username*: Option[string] password*: Option[string] type LacrosseConfig* = object host*: string port*: uint16 type InfluxConfig* = object host*: string port*: int authToken*: Option[string] powermetersDatabase*: Option[string] sensorsDatabase*: Option[string] type SmartiedConfig* = object frontendPort*: uint16 modbus*: Option[ModbusConfig] mqtt*: Option[MqttConfig] lacrosse*: Option[LacrosseConfig] influx*: Option[InfluxConfig] powermeterUpdateIntervalSec*: uint accessToken*: string type Config* = object devices*: Table[string, DeviceConfig] clientConfigs*: Table[string, JsonNode] serverConfig*: SmartiedConfig type Server* = object state*: Table[string, DeviceState] config*: Config type ResponseStatus* = enum Err, Ok type Response* = object status*: ResponseStatus data*: JsonNode type LacrosseMessage* = object id*: string temp*: float32 hum*: float32 weakBatt*: int type modbus* = pointer