示例#1
0
class SimpleDescriptor(t.EzspStruct):
    _fields = [
        ('endpoint', t.uint8_t),
        ('profile', t.uint16_t),
        ('device_type', t.uint16_t),
        ('device_version', t.uint8_t),
        ('input_clusters', t.LVList(t.uint16_t)),
        ('output_clusters', t.LVList(t.uint16_t)),
    ]
示例#2
0
def test_size_prefixed_simple_descriptor():
    sd = types.SizePrefixedSimpleDescriptor()
    sd.endpoint = t.uint8_t(1)
    sd.profile = t.uint16_t(2)
    sd.device_type = t.uint16_t(3)
    sd.device_version = t.uint8_t(4)
    sd.input_clusters = t.LVList(t.uint16_t)([t.uint16_t(5), t.uint16_t(6)])
    sd.output_clusters = t.LVList(t.uint16_t)([t.uint16_t(7), t.uint16_t(8)])

    ser = sd.serialize()
    assert ser[0] == len(ser) - 1

    sd2, data = types.SizePrefixedSimpleDescriptor.deserialize(ser)
    assert sd.input_clusters == sd2.input_clusters
    assert sd.output_clusters == sd2.output_clusters
示例#3
0
class Groups(Cluster):
    """Attributes and commands for group configuration and
    manipulation."""
    cluster_id = 0x0004
    attributes = {
        0x0000: ('name_support', t.uint8_t),  # bitmap8
    }
    server_commands = {
        0x0000: ('add', (t.uint16_t, t.LVBytes), False),
        0x0001: ('view', (t.uint16_t, ), False),
        0x0002: ('get_membership', (t.LVList(t.uint16_t), ), False),
        0x0003: ('remove', (t.uint16_t, ), False),
        0x0004: ('remove_all', (), False),
        0x0005: ('add_if_identifying', (t.uint16_t, t.LVBytes), False),
    }
    client_commands = {
        0x0000: ('add_response', (t.uint8_t, t.uint16_t), True),
        0x0001: ('view_response', (t.uint8_t, t.uint16_t, t.LVBytes), True),
        0x0002: ('get_membership_response', (t.uint8_t, t.LVList(t.uint16_t)), True),
        0x0003: ('remove_response', (t.uint8_t, t.uint16_t), True),
    }
示例#4
0
class PowerProfile(Cluster):
    cluster_id = 0x001a
    attributes = {
        0x0000: ('total_profile_num', t.uint8_t),
        0x0001: ('multiple_scheduling', t.uint8_t),
        0x0002: ('energy_formatting', t.uint8_t),  # bitmap8
        0x0003: ('energy_remote', t.Bool),
        0x0004: ('schedule_mode', t.uint8_t),  # bitmap8
    }

    class ScheduleRecord(t.EzspStruct):
        _fields = [
            ('phase_id', t.uint8_t),
            ('scheduled_time', t.uint16_t),
        ]

    class PowerProfilePhase(t.EzspStruct):
        _fields = [
            ('energy_phase_id', t.uint8_t),
            ('macro_phase_id', t.uint8_t),
            ('expected_duration', t.uint16_t),
            ('peak_power', t.uint16_t),
            ('energy', t.uint16_t),
        ]

    class PowerProfile(t.EzspStruct):
        _fields = [
            ('power_profile_id', t.uint8_t),
            ('energy_phase_id', t.uint8_t),
            ('power_profile_remote_control', t.Bool),
            ('power_profile_state', t.uint8_t),
        ]

    server_commands = {
        0x0000: ('power_profile_request', (t.uint8_t, ), False),
        0x0001: ('power_profile_state_request', (), False),
        0x0002: ('get_power_profile_price_response', (t.uint8_t, t.uint16_t, t.uint32_t, t.uint8_t), True),
        0x0003: ('get_overall_schedule_price_response', (t.uint16_t, t.uint32_t, t.uint8_t), True),
        0x0004: ('energy_phases_schedule_notification', (t.uint8_t, t.LVList(ScheduleRecord)), False),
        0x0005: ('energy_phases_schedule_response', (t.uint8_t, t.LVList(ScheduleRecord)), True),
        0x0006: ('power_profile_schedule_constraints_request', (t.uint8_t, ), False),
        0x0007: ('energy_phases_schedule_state_request', (t.uint8_t, ), False),
        0x0008: ('get_power_profile_price_extended_response', (t.uint8_t, t.uint16_t, t.uint32_t, t.uint8_t), True),
    }
    client_commands = {
        0x0000: ('power_profile_notification', (t.uint8_t, t.uint8_t, t.LVList(PowerProfilePhase)), False),
        0x0001: ('power_profile_response', (t.uint8_t, t.uint8_t, t.LVList(PowerProfilePhase)), True),
        0x0002: ('power_profile_state_response', (t.LVList(PowerProfile), ), True),
        0x0003: ('get_power_profile_price', (t.uint8_t, ), False),
        0x0004: ('power_profile_state_notification', (t.LVList(PowerProfile), ), False),
        0x0005: ('get_overall_schedule_price', (), False),
        0x0006: ('energy_phases_schedule_request', (), False),
        0x0007: ('energy_phases_schedule_state_response', (t.uint8_t, t.uint8_t), True),
        0x0008: ('energy_phases_schedule_state_notification', (t.uint8_t, t.uint8_t), False),
        0x0009: ('power_profile_schedule_constraints_notification', (t.uint8_t, t.uint16_t, t.uint16_t), False),
        0x000a: ('power_profile_schedule_constraints_response', (t.uint8_t, t.uint16_t, t.uint16_t), True),
        0x000b: ('get_power_profile_price_extended', (t.uint8_t, t.uint8_t, t.uint16_t), False),
    }
示例#5
0
class Scenes(Cluster):
    """Attributes and commands for scene configuration and
    manipulation."""
    cluster_id = 0x0005
    ep_attribute = 'scenes'
    attributes = {
        # Scene Management Information
        0x0000: ('count', t.uint8_t),
        0x0001: ('current_scene', t.uint8_t),
        0x0002: ('current_group', t.uint16_t),
        0x0003: ('scene_valid', t.Bool),
        0x0004: ('name_support', t.uint8_t),  # bitmap8
        0x0005: ('last_configured_by', t.EmberEUI64),
    }
    server_commands = {
        0x0000: ('add', (
            t.uint16_t,
            t.uint8_t,
            t.uint16_t,
            t.LVBytes,
        ), False),  # + extension field sets
        0x0001: ('view', (t.uint16_t, t.uint8_t), False),
        0x0002: ('remove', (t.uint16_t, t.uint8_t), False),
        0x0003: ('remove_all', (t.uint16_t, ), False),
        0x0004: ('store', (t.uint16_t, t.uint8_t), False),
        0x0005: ('recall', (t.uint16_t, t.uint8_t), False),
        0x0006: ('get_scene_membership', (t.uint16_t, ), False),
        0x0040: ('enhanced_add', (), False),
        0x0041: ('enhanced_view', (), False),
        0x0042: ('copy', (), False),
    }
    client_commands = {
        0x0000: ('add_response', (t.uint8_t, t.uint16_t, t.uint8_t), True),
        0x0001: ('view_response', (
            t.uint8_t,
            t.uint16_t,
            t.uint8_t,
        ), True),  # + 3 more optionals
        0x0002: ('remove_response', (t.uint8_t, t.uint16_t, t.uint8_t), True),
        0x0003: ('remove_all_response', (t.uint8_t, t.uint16_t), True),
        0x0004: ('store_response', (t.uint8_t, t.uint16_t, t.uint8_t), True),
        0x0006:
        ('get_scene_membership_response', (t.uint8_t, t.uint8_t, t.uint16_t,
                                           t.LVList(t.uint8_t)), True),
        0x0040: ('enhanced_add_response', (), True),
        0x0041: ('enhanced_view_response', (), True),
        0x0042: ('copy_response', (), True),
    }
示例#6
0
 def handle_route_record(
         self,
         nwk: t.EmberNodeId,
         ieee: t.EmberEUI64,
         lqi: t.uint8_t,
         rssi: t.int8s,
         relays: t.LVList(t.EmberNodeId),
 ) -> None:
     LOGGER.debug("Processing route record request: %s",
                  (nwk, ieee, lqi, rssi, relays))
     try:
         dev = self.get_device(ieee=ieee)
     except KeyError:
         LOGGER.debug("Why we don't have a device for %s ieee and %s NWK",
                      ieee, nwk)
         self.handle_join(nwk, ieee, 0)
         return
     dev.relays = relays
示例#7
0
NWKI = ('NWKAddrOfInterest', t.uint16_t)
IEEE = ('IEEEAddr', t.EmberEUI64)
STATUS = ('Status', t.uint8_t)

CLUSTERS = {
    # Device and Service Discovery Server Requests
    0x0000: ('NWK_addr_req', (IEEE, ('RequestType', t.uint8_t), ('StartIndex',
                                                                 t.uint8_t))),
    0x0001: ('IEEE_addr_req', (NWKI, ('RequestType', t.uint8_t), ('StartIndex',
                                                                  t.uint8_t))),
    0x0002: ('Node_Desc_req', (NWKI, )),
    0x0003: ('Power_Desc_req', (NWKI, )),
    0x0004: ('Simple_Desc_req', (NWKI, ('EndPoint', t.uint8_t))),
    0x0005: ('Active_EP_req', (NWKI, )),
    0x0006: ('Match_Desc_req', (NWKI, ('ProfileID', t.uint16_t),
                                ('InClusterList', t.LVList(t.uint16_t)),
                                ('OutClusterList', t.LVList(t.uint16_t)))),
    # 0x0010: ('Complex_Desc_req', (NWKI, )),
    0x0011: ('User_Desc_req', (NWKI, )),
    0x0012: ('Discovery_Cache_req', (NWK, IEEE)),
    0x0013: ('Device_annce', (NWK, IEEE, ('Capability', t.uint8_t))),
    0x0014:
    ('User_Desc_set', (NWKI, ('UserDescriptor',
                              t.fixed_list(16,
                                           t.uint8_t)))),  # Really a string
    0x0015: ('System_Server_Discovery_req', (('ServerMask', t.uint16_t), )),
    0x0016: ('Discovery_store_req',
             (NWK, IEEE, ('NodeDescSize', t.uint8_t),
              ('PowerDescSize', t.uint8_t), ('ActiveEPSize', t.uint8_t),
              ('SimpleDescSizeList', t.LVList(t.uint8_t)))),
    0x0017:
示例#8
0
def test_lvlist():
    d, r = t.LVList(t.uint8_t).deserialize(b'\x0412345')
    assert r == b'5'
    assert d == list(map(ord, '1234'))
    assert t.LVList(t.uint8_t).serialize(d) == b'\x041234'
示例#9
0
def test_lvlist():
    d, r = t.LVList(t.uint8_t).deserialize(b"\x0412345")
    assert r == b"5"
    assert d == list(map(ord, "1234"))
    assert t.LVList(t.uint8_t).serialize(d) == b"\x041234"
示例#10
0
 'messageSentHandler': (0x3F, (), (t.EmberOutgoingMessageType, t.uint16_t,
                                   t.EmberApsFrame, t.uint8_t,
                                   t.EmberStatus, t.LVBytes)),
 'sendManyToOneRouteRequest': (0x41, (t.uint16_t, t.uint8_t),
                               (t.EmberStatus, )),
 'pollForData': (0x42, (t.uint16_t, t.EmberEventUnits, t.uint8_t),
                 (t.EmberStatus, )),
 'pollCompleteHandler': (0x43, (), (t.EmberStatus, )),
 'pollHandler': (0x44, (), (t.EmberNodeId, )),
 'incomingSenderEui64Handler': (0x62, (), (t.EmberEUI64, )),
 'incomingMessageHandler':
 (0x45, (), (t.EmberIncomingMessageType, t.EmberApsFrame, t.uint8_t,
             t.int8s, t.EmberNodeId, t.uint8_t, t.uint8_t, t.LVBytes)),
 'incomingRouteRecordHandler': (0x59, (), (t.EmberNodeId, t.EmberEUI64,
                                           t.uint8_t, t.int8s,
                                           t.LVList(t.EmberNodeId))),
 'changeSourceRouteHandler': (0xC4, (), (t.EmberNodeId, t.EmberNodeId,
                                         t.Bool)),
 # TODO: LVBytes in setSourceRoute is really a list of uint16_t,
 #       serializing the frame will produce something the NCP will fail
 #       on, since the NCP expects the length to be number of items in the
 #       list
 # 'setSourceRoute': (0x5A, (t.EmberNodeId, t.LVBytes), (t.EmberStatus, )),
 'incomingManyToOneRouteRequestHandler':
 (0x7D, (), (t.EmberNodeId, t.EmberEUI64, t.uint8_t)),
 'incomingRouteErrorHandler': (0x80, (), (t.EmberStatus, t.EmberNodeId)),
 'addressTableEntryIsActive': (0x5B, (t.uint8_t, ), (t.Bool, )),
 'setAddressTableRemoteEui64': (0x5C, (t.uint8_t, t.EmberEUI64),
                                (t.EmberStatus, )),
 'setAddressTableRemoteNodeId': (0x5D, (t.uint8_t, t.EmberNodeId), ()),
 'getAddressTableRemoteEui64': (0x5E, (t.uint8_t, ), (t.EmberEUI64, )),
示例#11
0
     (
         t.EmberIncomingMessageType,
         t.EmberApsFrame,
         t.uint8_t,
         t.int8s,
         t.EmberNodeId,
         t.uint8_t,
         t.uint8_t,
         t.LVBytes,
     ),
 ),
 "incomingRouteRecordHandler": (
     0x59,
     (),
     (t.EmberNodeId, t.EmberEUI64, t.uint8_t, t.int8s,
      t.LVList(t.EmberNodeId)),
 ),
 "changeSourceRouteHandler": (0xC4, (), (t.EmberNodeId, t.EmberNodeId,
                                         t.Bool)),
 "setSourceRoute": (
     0x5A,
     (t.EmberNodeId, t.LVList(t.EmberNodeId)),
     (t.EmberStatus, ),
 ),
 "incomingManyToOneRouteRequestHandler": (
     0x7D,
     (),
     (t.EmberNodeId, t.EmberEUI64, t.uint8_t),
 ),
 "incomingRouteErrorHandler": (0x80, (), (t.EmberStatus, t.EmberNodeId)),
 "addressTableEntryIsActive": (0x5B, (t.uint8_t, ), (t.Bool, )),
示例#12
0
 'remoteDeleteBindingHandler': (0x32, (), (t.uint8_t, t.EmberStatus)),
 # 8. Messaging Frames
 'maximumPayloadLength': (0x33, (), (t.uint8_t, )),
 'sendUnicast': (0x34, (t.EmberOutgoingMessageType, t.EmberNodeId, t.EmberApsFrame, t.uint8_t, t.LVBytes), (t.EmberStatus, t.uint8_t)),
 'sendBroadcast': (0x36, (t.EmberNodeId, t.EmberApsFrame, t.uint8_t, t.uint8_t, t.LVBytes), (t.EmberStatus, t.uint8_t)),
 'proxyBroadcast': (0x37, (t.EmberNodeId, t.EmberNodeId, t.uint8_t, t.EmberApsFrame, t.uint8_t, t.uint8_t, t.LVBytes), (t.EmberStatus, t.uint8_t)),
 'sendMulticast': (0x38, (t.EmberApsFrame, t.uint8_t, t.uint8_t, t.uint8_t, t.LVBytes), (t.EmberStatus, t.uint8_t)),
 'sendReply': (0x39, (t.EmberNodeId, t.EmberApsFrame, t.LVBytes), (t.EmberStatus, )),
 'messageSentHandler': (0x3F, (), (t.EmberOutgoingMessageType, t.uint16_t, t.EmberApsFrame, t.uint8_t, t.EmberStatus, t.LVBytes)),
 'sendManyToOneRouteRequest': (0x41, (t.uint16_t, t.uint8_t), (t.EmberStatus, )),
 'pollForData': (0x42, (t.uint16_t, t.EmberEventUnits, t.uint8_t), (t.EmberStatus, )),
 'pollCompleteHandler': (0x43, (), (t.EmberStatus, )),
 'pollHandler': (0x44, (), (t.EmberNodeId, )),
 'incomingSenderEui64Handler': (0x62, (), (t.EmberEUI64, )),
 'incomingMessageHandler': (0x45, (), (t.EmberIncomingMessageType, t.EmberApsFrame, t.uint8_t, t.int8s, t.EmberNodeId, t.uint8_t, t.uint8_t, t.LVBytes)),
 'incomingRouteRecordHandler': (0x59, (), (t.EmberNodeId, t.EmberEUI64, t.uint8_t, t.int8s, t.LVList(t.EmberNodeId))),
 'changeSourceRouteHandler': (0xC4, (), (t.EmberNodeId, t.EmberNodeId, t.Bool)),
 # TODO: LVBytes in setSourceRoute is really a list of uint16_t,
 #       serializing the frame will produce something the NCP will fail
 #       on, since the NCP expects the length to be number of items in the
 #       list
 # 'setSourceRoute': (0x5A, (t.EmberNodeId, t.LVBytes), (t.EmberStatus, )),
 'incomingManyToOneRouteRequestHandler': (0x7D, (), (t.EmberNodeId, t.EmberEUI64, t.uint8_t)),
 'incomingRouteErrorHandler': (0x80, (), (t.EmberStatus, t.EmberNodeId)),
 'addressTableEntryIsActive': (0x5B, (t.uint8_t, ), (t.Bool, )),
 'setAddressTableRemoteEui64': (0x5C, (t.uint8_t, t.EmberEUI64), (t.EmberStatus, )),
 'setAddressTableRemoteNodeId': (0x5D, (t.uint8_t, t.EmberNodeId), ()),
 'getAddressTableRemoteEui64': (0x5E, (t.uint8_t, ), (t.EmberEUI64, )),
 'getAddressTableRemoteNodeId': (0x5F, (t.uint8_t, ), (t.EmberNodeId, )),
 'setExtendedTimeout': (0x7E, (t.EmberEUI64, t.Bool), ()),
 'getExtendedTimeout': (0x7F, (t.EmberEUI64, ), (t.Bool, )),
示例#13
0
 'messageSentHandler': (0x3F, (), (t.EmberOutgoingMessageType, t.uint16_t,
                                   t.EmberApsFrame, t.uint8_t,
                                   t.EmberStatus, t.LVBytes)),
 'sendManyToOneRouteRequest': (0x41, (t.uint16_t, t.uint8_t),
                               (t.EmberStatus, )),
 'pollForData': (0x42, (t.uint16_t, t.EmberEventUnits, t.uint8_t),
                 (t.EmberStatus, )),
 'pollCompleteHandler': (0x43, (), (t.EmberStatus, )),
 'pollHandler': (0x44, (), (t.EmberNodeId, )),
 'incomingSenderEui64Handler': (0x62, (), (t.EmberEUI64, )),
 'incomingMessageHandler':
 (0x45, (), (t.EmberIncomingMessageType, t.EmberApsFrame, t.uint8_t,
             t.int8s, t.EmberNodeId, t.uint8_t, t.uint8_t, t.LVBytes)),
 'incomingRouteRecordHandler': (0x59, (), (t.EmberNodeId, t.EmberEUI64,
                                           t.uint8_t, t.int8s,
                                           t.LVList(t.EmberNodeId))),
 'changeSourceRouteHandler': (0xC4, (), (t.EmberNodeId, t.EmberNodeId,
                                         t.Bool)),
 'setSourceRoute': (0x5A, (t.EmberNodeId, t.LVList(t.EmberNodeId)),
                    (t.EmberStatus, )),
 'incomingManyToOneRouteRequestHandler':
 (0x7D, (), (t.EmberNodeId, t.EmberEUI64, t.uint8_t)),
 'incomingRouteErrorHandler': (0x80, (), (t.EmberStatus, t.EmberNodeId)),
 'addressTableEntryIsActive': (0x5B, (t.uint8_t, ), (t.Bool, )),
 'setAddressTableRemoteEui64': (0x5C, (t.uint8_t, t.EmberEUI64),
                                (t.EmberStatus, )),
 'setAddressTableRemoteNodeId': (0x5D, (t.uint8_t, t.EmberNodeId), ()),
 'getAddressTableRemoteEui64': (0x5E, (t.uint8_t, ), (t.EmberEUI64, )),
 'getAddressTableRemoteNodeId': (0x5F, (t.uint8_t, ), (t.EmberNodeId, )),
 'setExtendedTimeout': (0x7E, (t.EmberEUI64, t.Bool), ()),
 'getExtendedTimeout': (0x7F, (t.EmberEUI64, ), (t.Bool, )),
示例#14
0
class RSSILocation(Cluster):
    """Attributes and commands that provide a means for
    exchanging location information and channel parameters
    among devices."""
    cluster_id = 0x000b
    ep_attribute = 'rssi_location'
    attributes = {
        # Location Information
        0x0000: ('type', t.uint8_t),
        0x0001: ('method', t.uint8_t),  # enum8
        0x0002: ('age', t.uint16_t),
        0x0003: ('quality_measure', t.uint8_t),
        0x0004: ('num_of_devices', t.uint8_t),
        # Location Settings
        0x0010: ('coordinate1', t.int16s),
        0x0011: ('coordinate2', t.int16s),
        0x0012: ('coordinate3', t.int16s),
        0x0013: ('power', t.int16s),
        0x0014: ('path_loss_exponent', t.uint16_t),
        0x0015: ('reporting_period', t.uint16_t),
        0x0016: ('calc_period', t.uint16_t),
        0x0017: ('num_rssi_measurements', t.uint16_t),
    }
    server_commands = {
        0x0000: ('set_absolute_location', (t.int16s, t.int16s, t.int16s,
                                           t.int8s, t.uint16_t), False),
        0x0001: ('set_dev_config', (t.int16s, t.uint16_t, t.uint16_t,
                                    t.uint8_t, t.uint16_t), False),
        0x0002: ('get_dev_config', (t.EmberEUI64, ), False),
        0x0003:
        ('get_location_data', (t.uint8_t, t.uint64_t, t.EmberEUI64), False),
        0x0004: ('rssi_response', (t.EmberEUI64, t.int16s, t.int16s, t.int16s,
                                   t.int8s, t.uint8_t), True),
        0x0005: ('send_pings', (t.EmberEUI64, t.uint8_t, t.uint16_t), False),
        0x0006: ('anchor_node_announce', (t.EmberEUI64, t.int16s, t.int16s,
                                          t.int16s), False),
    }

    class NeighborInfo(t.EzspStruct):
        _fields = [
            ('neighbor', t.EmberEUI64),
            ('x', t.int16s),
            ('y', t.int16s),
            ('z', t.int16s),
            ('rssi', t.int8s),
            ('num_measurements', t.uint8_t),
        ]

    client_commands = {
        0x0000:
        ('dev_config_response', (t.uint8_t, t.int16s, t.uint16_t, t.uint16_t,
                                 t.uint8_t, t.uint16_t), True),
        0x0001: ('location_data_response',
                 (t.uint8_t, t.uint8_t, t.int16s, t.int16s, t.int16s,
                  t.uint16_t, t.uint8_t, t.uint8_t, t.uint16_t), True),
        0x0002: ('location_data_notification', (), False),
        0x0003: ('compact_location_data_notification', (), False),
        0x0004: ('rssi_ping', (t.uint8_t, ), False),  # data8
        0x0005: ('rssi_req', (), False),
        0x0006: ('report_rssi_measurements', (
            t.EmberEUI64,
            t.LVList(NeighborInfo),
        ), False),
        0x0007: ('request_own_location', (t.EmberEUI64, ), False),
    }