# fmt: off SensorPropertyId = FieldAdapter( Select( EnumAdapter(Int16ul, PropertyID), Int16ul), Int16ul ) SensorGetMinimal = Struct() SensorGetOptional = Struct( "property_id" / SensorPropertyId, ) SensorGet = NamedSelect( optional=SensorGetOptional, minimal=SensorGetMinimal ) SensorSettingsGet = Struct( "sensor_property_id" / SensorPropertyId, ) SensorSettingGet = Struct( Embedded(SensorSettingsGet), "sensor_setting_property_id" / SensorPropertyId, ) class SensorSettingRawMixin: def _parse_sensor_setting(self, stream, context, path, sensor_setting_property_id, **kwargs): try: sensor_setting_property_id = PropertyID(sensor_setting_property_id)
def __repr__(self): return str(self.value) # fmt: off LightCTLGet = Struct() LightCTLDefault = Struct("ctl_lightness" / Int16ul, "ctl_temperature" / Int16ul, "ctl_delta_uv" / Int16ul) LightCTLSetMinimal = Struct(Embedded(LightCTLDefault), "tid" / Int8ul) LightCTLSetOptional = Struct(Embedded(LightCTLSetMinimal), Embedded(OptionalSetParameters)) LightCTLSet = NamedSelect(optional=LightCTLSetOptional, minimal=LightCTLSetMinimal) LightCTLStatusMinimal = Struct( "present_ctl_lightness" / Int16ul, "present_ctl_temperature" / Int16ul, ) LightCTLStatusOptional = Struct( Embedded(LightCTLStatusMinimal), "target_ctl_lightness" / Int16ul, "target_ctl_temperature" / Int16ul, "remaining_time" / TransitionTimeAdapter(TransitionTime, allow_unknown=True)) LightCTLStatus = NamedSelect(optional=LightCTLStatusOptional, minimal=LightCTLStatusMinimal) LightCTLTemperatureStatusMinimal = Struct(
NodeIdentityAdapter = EnumAdapter(Int8ul, NodeIdentity) FriendAdapter = EnumAdapter(Int8ul, Friend) TTL = RangeValidator(Int8ul, max_value=0x7F) # fmt: off SIGModelId = Struct("model_id" / Int16ul, ) VendorModelId = Struct( "vendor_id" / Int16ul, "model_id" / Int16ul, ) ModelId = NamedSelect(vendor=VendorModelId, sig=SIGModelId) # fmt: on class AddressType(enum.Enum): UNASSIGNED = 0 UNICAST = 1 GROUP = 2 VIRTUAL = 3 RFU = 4 ALL_PROXIES = 5 ALL_FRIENDS = 6 ALL_RELAYS = 7 ALL_NODES = 8
TimeMinimal = Struct("tai_seconds" / BytesInteger(5, swapped=True), ) TimeOptional = Struct( "tai_seconds" / BytesInteger(5, swapped=True), StopIf(this.tai_seconds == 0), "subsecond" / Int8ul, "uncertainty" / Int8ul, *EmbeddedBitStruct("_", "tai_utc_delta" / BitsInteger(15), "time_authority" / Flag, reversed=True), "time_zone_offset" / Int8ul, ) Time = NamedSelect( optional=TimeOptional, minimal=TimeMinimal, ) class TimeAdapter(Adapter): def _decode(self, obj, context, path): if obj["tai_seconds"] == 0: return Container(date=None, tai_utc_delta=None, time_authority=None, uncertainty=None) time_zone = mesh_time_zone_offset_to_timedelta(obj["time_zone_offset"]) full_recv_time = obj["tai_seconds"] + subsecond_to_seconds( obj["subsecond"]) + MESH_UNIX_EPOCH_DIFF + int( time_zone.total_seconds()) recv_date = datetime.fromtimestamp(full_recv_time, timezone(time_zone))
SceneGet = Struct() SceneRecallMinimal = Struct( "scene_number" / ExprValidator(Int16ul, obj_ > 0), "tid" / Int8ul, ) SceneRecallWithTransition = Struct( "scene_number" / ExprValidator(Int16ul, obj_ > 0), "tid" / Int8ul, "transition_time" / TransitionTimeAdapter(TransitionTime, allow_unknown=False), "delay" / Delay(Int8ul), ) SceneRecall = NamedSelect(optional=SceneRecallWithTransition, minimal=SceneRecallMinimal) SceneStatusMinimal = Struct( "status_code" / EnumAdapter(Int8ul, SceneStatusCode), "current_scene" / Int16ul) SceneStatusWithTargetScene = Struct( "status_code" / EnumAdapter(Int8ul, SceneStatusCode), "current_scene" / Int16ul, "target_scene" / Int16ul, "remaining_time" / TransitionTimeAdapter(TransitionTime, allow_unknown=False), ) SceneStatus = NamedSelect(optional=SceneStatusWithTargetScene, minimal=SceneStatusMinimal)
LightLightnessDefault = Struct( "lightness" / Int16ul ) LightLightnessStatusMinimal = Struct( "present_lightness" / Int16ul ) LightLightnessStatusOptional = Struct( Embedded(LightLightnessStatusMinimal), "target_lightness" / Int16ul, "remaining_time" / TransitionTimeAdapter(TransitionTime, allow_unknown=True) ) LightLightnessStatus = NamedSelect( optional=LightLightnessStatusOptional, minimal=LightLightnessStatusMinimal ) LightLightnessRange = Struct( "range_min" / Int16ul, "range_max" / Int16ul, ) LightLightnessRangeStatus = Struct( "status" / StatusCodeAdapter, Embedded(LightLightnessRange) ) LightLightnessSetMinimal = Struct( "lightness" / Int16ul, "tid" / Int8ul
"max_hops" / ConfigHeartbeatHops) NetworkDiagnosticSetupServerPublicationSetMinimal = Struct( "destination" / UnicastUnassignedGroupAddress, "count" / Int16ul, "period" / TransitionTime, "ttl" / TTL, "net_key_index" / Int12ul, ) NetworkDiagnosticSetupServerPublicationSetOptional = Struct( Embedded(NetworkDiagnosticSetupServerPublicationSetMinimal), "features" / ConfigHeartbeatPublicationFeatures) NetworkDiagnosticSetupServerPublicationSet = NamedSelect( optional=NetworkDiagnosticSetupServerPublicationSetOptional, minimal=NetworkDiagnosticSetupServerPublicationSetMinimal, ) NetworkDiagnosticSetupServerPublicationStatus = NetworkDiagnosticSetupServerPublicationSet NetworkDiagnosticServerSubscriptionGet = Struct() NetworkDiagnosticServerSubscriptionSet = Struct( "destination" / UnicastUnassignedGroupAddress, "period" / Int16ul) NetworkDiagnosticServerSubscriptionStatus = Struct( "destination" / UnicastUnassignedGroupAddress, "period" / Int16ul, "max_record_count" / Int8ul, "record" / GreedyRange(RegistryRecord)) NetworkDiagnosticServerRadioStatGet = Struct()
IvIndexGet = Struct() IvIndexStatus = Struct("ivindex" / Int32ul) GarbageCollectorCounterGet = Struct() GarbageCollectorCounterStatus = Struct("counter" / Int16ul) ArapSize16 = Struct("capacity" / Int16ul, "size" / Int16ul) ArapSize8 = Struct("capacity" / Int8ul, "size" / Int8ul) ArapListSizeGet = Struct() ArapListSizeStatus = NamedSelect( new=ArapSize16, old=ArapSize8, ) ArapListContentGet = Struct("page" / Int8ul) ArapNode = ByteSwapped( BitStruct( "sequence" / Bytewise(Int24ub), "ivi" / BitsInteger(1), "address" / BitsInteger(15), )) ArapListContentStatus = Struct("current_page" / Int8ul, "last_page" / Int8ul, "nodes" / GreedyRange(ArapNode)) DebugParams = SwitchStruct(
# fmt: off GenericOnOffGet = Struct() GenericOnOffSetMinimal = Struct("onoff" / Int8ul, "tid" / Int8ul) GenericOnOffSetOptional = Struct( "onoff" / Int8ul, "tid" / Int8ul, "transition_time" / TransitionTimeAdapter(TransitionTime, allow_unknown=False), "delay" / Delay(Int8ul), ) GenericOnOffSet = NamedSelect(optional=GenericOnOffSetOptional, minimal=GenericOnOffSetMinimal) GenericOnOffStatusMinimal = Struct("present_onoff" / Int8ul) GenericOnOffStatusOptional = Struct( "present_onoff" / Int8ul, "target_onoff" / Int8ul, "remaining_time" / TransitionTimeAdapter(TransitionTime, allow_unknown=True), ) GenericOnOffStatus = NamedSelect(optional=GenericOnOffStatusOptional, minimal=GenericOnOffStatusMinimal) GenericOnOffMessage = SwitchStruct( "opcode" / Opcode(GenericOnOffOpcode),
GENERIC_LEVEL_STATUS = 0x8208 GENERIC_DELTA_SET = 0x8209 GENERIC_DELTA_SET_UNACKNOWLEDGED = 0x820A GENERIC_MOVE_SET = 0x820B GENERIC_MOVE_SET_UNACKNOWLEDGED = 0x820C # fmt: off GenericLevelGet = Struct() GenericLevelSetMinimal = Struct("level" / Int16sl, "tid" / Int8ul) GenericLevelSetOptional = Struct(Embedded(GenericLevelSetMinimal), Embedded(OptionalSetParameters)) GenericLevelSet = NamedSelect(optional=GenericLevelSetOptional, minimal=GenericLevelSetMinimal) GenericDeltaSetMinimal = Struct("delta_level" / Int32sl, "tid" / Int8ul) GenericDeltaSetOptional = Struct(Embedded(GenericDeltaSetMinimal), Embedded(OptionalSetParameters)) GenericDeltaSet = NamedSelect(optional=GenericDeltaSetOptional, minimal=GenericDeltaSetMinimal) GenericMoveSetMinimal = Struct("delta_level" / Int16sl, "tid" / Int8ul) GenericMoveSetOptional = Struct(Embedded(GenericMoveSetMinimal), Embedded(OptionalSetParameters)) GenericMoveSet = NamedSelect(optional=GenericMoveSetOptional,