class NodeInfoCachedReport(Message): """Command Class message COMMAND_CLASS_NETWORK_MANAGEMENT_PROXY NODE_INFO_CACHED_REPORT""" NAME = "NODE_INFO_CACHED_REPORT" class Status(IntEnum): """Node info status""" OK = 0x00 NOT_RESPONDING = 0x01 UNKNOWN = 0x02 attributes = ( ("seqNo", uint8_t), ("status", enum_t(Status, uint4_t)), ("age", uint4_t), ("listening", flag_t), ("zwaveProtocolSpecific", reserved_t(7)), ("optFunc", flag_t), ("zwaveProtocolSpecific", reserved_t(7)), ("-", reserved_t(8)), ("basicDeviceClass", uint8_t), ("genericDeviceClass", uint8_t), ("specificDeviceClass", uint8_t), ("commandClass", bytes_t), )
class ZIPPacketOption(AttributesMixin): """ZIP Packet option""" attributes = ( ("critical", flag_t), ("optionType", enum_t(ZIPPacketOptionType, uint7_t)), ("optionData", ZIPPacketOptionData), ) def parse_optionData(self, stream: BitStreamReader): # pylint: disable=invalid-name """Parse attribute optionData""" clsType = ZIPPacketOptionData length = stream.byte() data = stream.value(length) if self.optionType == ZIPPacketOptionType.MAINTENANCE_REPORT: clsType = ZIPPacketOptionMaintenanceReport elif self.optionType == ZIPPacketOptionType.ENCAPSULATION_FORMAT_INFORMATION: clsType = ZIPPacketOptionEncapsulationFormatInfo elif self.optionType == ZIPPacketOptionType.EXPECTED_DELAY: clsType = ZIPPacketOptionExpectedDelay cls = clsType() if hasattr(cls, "parseAttributes"): cls.parseAttributes(BitStreamReader(data)) elif hasattr(cls, "__setstate__"): data = clsType.deserialize(BitStreamReader(data)) cls.__setstate__(data) else: value = clsType.deserialize(BitStreamReader(data)) return clsType(value) return cls
def test_enum_t(): class MyEnum(Enum): FOO = 1 BAR = 2 MyEnum_t = enum_t(MyEnum, uint8_t) assert repr(MyEnum_t(1)) == "FOO (0x1)" assert repr(MyEnum_t(2)) == "BAR (0x2)" assert repr(MyEnum_t(3)) == "UNKNOWN (0x3)"
def test_enum_t_IntFlags(): class MyFlags(IntFlag): FOO = 1 BAR = 2 MyFlags_t = enum_t(MyFlags, uint8_t) assert repr(MyFlags_t(1)) == "MyFlags.FOO (1)" assert repr(MyFlags_t(2)) == "MyFlags.BAR (10)" assert repr(MyFlags_t(3)) == "MyFlags.BAR|FOO (11)"
class NodeAddKeysReport(Message): """Command Class message COMMAND_CLASS_NETWORK_MANAGEMENT_INCLUSION NODE_ADD_KEYS_REPORT""" NAME = "NODE_ADD_KEYS_REPORT" attributes = ( ("seqNo", uint8_t), ("-", reserved_t(7)), ("requestCSA", flag_t), ("requestedKeys", enum_t(Keys, uint8_t)), )
class NodeAddKeysSet(Message): """Command Class message COMMAND_CLASS_NETWORK_MANAGEMENT_INCLUSION NODE_ADD_KEYS_SET""" NAME = "NODE_ADD_KEYS_SET" attributes = ( ("seqNo", uint8_t), ("-", reserved_t(6)), ("grantCSA", flag_t), ("accept", flag_t), ("grantedKeys", enum_t(Keys, uint8_t)), )
class NodeRemoveStatus(Message): """Command Class message COMMAND_CLASS_NETWORK_MANAGEMENT_INCLUSION NODE_REMOVE_STATUS""" NAME = "NODE_REMOVE_STATUS" class Status(IntEnum): """Remove node status""" DONE = 0x06 FAILED = 0x07 attributes = ( ("seqNo", uint8_t), ("status", enum_t(Status, uint8_t)), ("nodeID", uint8_t), )
class NodeRemove(Message): """Command Class message COMMAND_CLASS_NETWORK_MANAGEMENT_INCLUSION NODE_REMOVE""" NAME = "NODE_REMOVE" class Mode(IntEnum): """Remove node mode""" ANY = 0x01 STOP = 0x05 attributes = ( ("seqNo", uint8_t), ("-", reserved_t(8)), ("mode", enum_t(Mode, uint8_t)), )
class FailedNodeRemoveStatus(Message): """Command Class message COMMAND_CLASS_NETWORK_MANAGEMENT_INCLUSION FAILED_NODE_REMOVE_STATUS""" NAME = "FAILED_NODE_REMOVE_STATUS" class Status(IntEnum): """Failed node remove status""" NOT_FOUND = 0x00 DONE = 0x01 REMOVE_FAIL = 0x02 attributes = ( ("seqNo", uint8_t), ("status", enum_t(Status, uint8_t)), ("nodeID", uint8_t), )
class NodeAdd(Message): """Command Class message COMMAND_CLASS_NETWORK_MANAGEMENT_INCLUSION NODE_ADD""" NAME = "NODE_ADD" class Mode(IntEnum): """Node add mode""" ANY = 0x01 STOP = 0x05 ANY_S2 = 0x07 attributes = ( ("seqNo", uint8_t), ("-", reserved_t(8)), ("mode", enum_t(Mode, uint8_t)), ("txOptions", uint8_t), )
class Queue(Message): """Command Class message COMMAND_CLASS_MAILBOX MAILBOX_QUEUE""" class Operation(IntEnum): """Mailbox Queue Operation enum""" PUSH = 0x00 POP = 0x01 WAITING = 0x02 PING = 0x03 ACK = 0x04 NACK = 0x05 QUEUE_FULL = 0x06 NAME = "QUEUE" attributes = ( ("-", reserved_t(4)), ("last", flag_t), ("operation", enum_t(Operation, uint3_t)), ("queueHandle", uint8_t), ("mailboxEntry", bytes_t), )
class IMELastWorkingRoute(IMEValue, AttributesMixin): """Last working route""" class Speed(IntEnum): """Communication speed""" SPEED_9_6_KBIT_S = 0x01 SPEED_40_KBIT_S = 0x02 SPEED_100_KBIT_S = 0x03 attributes = ( ("repeater1", uint8_t), ("repeater2", uint8_t), ("repeater3", uint8_t), ("repeater4", uint8_t), ("speed", enum_t(Speed, uint8_t)), ) @classmethod def load(cls, value): lastWorkingRoute = cls() lastWorkingRoute.parseAttributes(value) return lastWorkingRoute
class NodeAddStatus(Message): """Command Class message COMMAND_CLASS_NETWORK_MANAGEMENT_INCLUSION NODE_ADD_STATUS""" class Status(IntEnum): """Add node status""" NODE_FOUND = 0x02 # Note, not part of NodeAddStatus, only in Serial Api ADD_SLAVE = 0x03 # Note, not part of NodeAddStatus, only in Serial Api PROTOCOL_DONE = 0x05 # Note, not part of NodeAddStatus, only in Serial Api DONE = 0x06 FAILED = 0x07 SECURITY_FAILED = 0x09 NAME = "NODE_ADD_STATUS" attributes = ( ("seqNo", uint8_t), ("status", enum_t(Status, uint8_t)), ("-", reserved_t(8)), ("newNodeID", uint8_t), ("nodeInfoLength", uint8_t), ("listening", flag_t), ("zwaveProtocolSpecific", reserved_t(7)), ("optFunc", flag_t), ("zwaveProtocolSpecific", reserved_t(7)), ("basicDeviceClass", uint8_t), ("genericDeviceClass", uint8_t), ("specificDeviceClass", uint8_t), ("commandClass", list), ) def parse_commandClass(self, stream: BitStreamReader): # pylint: disable=invalid-name """Parse the length prefixed command""" length = self.nodeInfoLength - 7 if length > stream.bytesLeft(): return list(stream.remaining()) return list(stream.value(length))
MAILBOX_CONFIGURATION_REPORT = 0x03 MAILBOX_QUEUE = 0x04 MAILBOX_WAKEUP_NOTIFICATION = 0x05 MAILBOX_NODE_FAILING = 0x06 MAILBOX_QUEUE_FLUSH = 0x07 class Mode(IntFlag): """Mailbox mode enum""" DISABLE_MAILBOX = 0x00 ENABLE_MAILBOX_SERVICE = 0x01 ENABLE_MAILBOX_PROXY_FORWARDING = 0x02 Mode_t = enum_t(Mode, uint3_t) # pylint: disable=invalid-name @ZWaveMessage(COMMAND_CLASS_MAILBOX, MAILBOX_CONFIGURATION_GET) class ConfigurationGet(Message): """Command Class message COMMAND_CLASS_MAILBOX MAILBOX_CONFIGURATION_GET""" NAME = "CONFIGURATION_GET" @ZWaveMessage(COMMAND_CLASS_MAILBOX, MAILBOX_CONFIGURATION_REPORT) class ConfigurationReport(Message): """Command Class message COMMAND_CLASS_MAILBOX MAILBOX_CONFIGURATION_REPORT""" NAME = "CONFIGURATION_REPORT" attributes = (
) from . import ZWaveCommandClass, ZWaveMessage, ZWaveMessageHandler from .CommandClass import CommandClass, DictAttribute, VarDictAttribute _LOGGER = logging.getLogger(__name__) class Size(IntEnum): """Size enum for configurations""" SIZE_8_BIT = 1 SIZE_16_BIT = 2 SIZE_32_BIT = 4 Size_t = enum_t(Size, uint3_t) # pylint: disable=invalid-name @ZWaveMessage(COMMAND_CLASS_CONFIGURATION, CONFIGURATION_BULK_GET_V2) class BulkGet(Message): """Command Class message COMMAND_CLASS_CONFIGURATION CONFIGURATION_BULK_GET_V2""" NAME = "BULK_GET" attributes = (("parameterOffset", uint16_t), ("numberOfParameters", uint8_t)) @ZWaveMessage(COMMAND_CLASS_CONFIGURATION, CONFIGURATION_BULK_REPORT_V2) class BulkReport(Message): """Command Class message COMMAND_CLASS_CONFIGURATION CONFIGURATION_BULK_REPORT_V2"""
) from . import ZWaveMessage, ZWaveCommandClass from .CommandClass import CommandClass class MeterType(IntEnum): """Enum for Meter types""" ELECTRIC_METER = 0x01 GAS_METER = 0x02 WATER_METER = 0x03 HEATING_METER = 0x04 COOLING_METER = 0x05 MeterType_t = enum_t(MeterType, bits_t(5)) # pylint: disable=invalid-name class ElectricMeterScale(IntEnum): """Enum for the scales for electric meter""" KWH = 0x00 KVAH = 0x01 W = 0x02 PULSE_COUNT = 0x03 V = 0x04 A = 0x05 POWER_FACTOR = 0x06 MST = 0x07
VELOCITY = 0x06 BAROMETRIC_PRESSURE = 0x09 DEW_POINT = 0x0B RAIN_RATE = 0x0C WEIGHT = 0x0E VOLTAGE = 0x0F CO2 = 0x11 VOLUME = 0x13 # tank capacity UV = 0x1B LOUDNESS = 0x1E MOISTURE = 0x1F PM25 = 0x23 CO = 0x28 SensorType_t = enum_t(SensorType, uint8_t) # pylint: disable=invalid-name class SensorSupported(set): """Deserializer for sensor types returned in SUPPORTED_SENSOR_REPORT""" @classmethod def deserialize(cls, stream: BitStreamReader): """Deserialize types from stream""" supported = cls() value = int.from_bytes(stream.remaining(), byteorder="big", signed=False) i = 1 while value > 0: if value & 1 == 1: supported.add(SensorType(i))
class ApplicationBusy(Message): """Command Class message COMMAND_CLASS_APPLICATION_STATUS APPLICATION_BUSY""" NAME = "APPLICATION_BUSY" attributes = (("status", enum_t(Status, uint8_t)), ("waitTime", uint8_t))