Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new zigpy radio API #123

Merged
merged 18 commits into from
Jun 21, 2022
Merged

Implement new zigpy radio API #123

merged 18 commits into from
Jun 21, 2022

Conversation

puddly
Copy link
Contributor

@puddly puddly commented Jan 15, 2022

Untested implementation of zigpy/zigpy#848

The XBee API doesn't allow for any interesting data to be read from the coordinator (i.e. network key, frame counters, child tables) so unfortunately backup for this platform won't be possible for existing networks. Maybe the help of a second radio in router/end device mode...

@puddly
Copy link
Contributor Author

puddly commented May 25, 2022

@Adminiuga @Shulyaka could you test this PR out with some real XBee hardware?

All of the dependencies are backwards compatible with ZHA so it's expected to "just work" and log some extra info on startup:

pip install \
    git+https://github.com/puddly/zigpy.git@puddly/new-radio-settings-api \
    git+https://github.com/puddly/zigpy-cli.git@puddly/zigpy-radio-api \
    git+https://github.com/puddly/zigpy-znp.git@puddly/new-radio-settings-api \
    git+https://github.com/puddly/zigpy-deconz.git@puddly/new-radio-api \
    git+https://github.com/puddly/zigpy-xbee.git@puddly/new-radio-api \
    git+https://github.com/puddly/zigpy-zigate.git@puddly/new-radio-api \
    git+https://github.com/puddly/bellows.git@puddly/zigpy-radio-api

hass --skip-pip  # so HA doesn't downgrade the deps on startup

@Shulyaka
Copy link
Contributor

Hi @puddly

What do you want us to test? Just normal operations or some specific test cases?

@puddly
Copy link
Contributor Author

puddly commented May 25, 2022

The only notable changes are to network formation, detecting when a network is not formed, and reading out network settings (the few that the XBee command set allows you to read).

@Shulyaka
Copy link
Contributor

Shulyaka commented Jun 8, 2022

Hi @puddly
Sorry for the delay.
I've tested startup, it correctly detects the existing network.
However I've found something interesting: it opens a join window on startup due to CB2, which might be a security issue (a malicious device could wait for a next restart, then attach to the network and get the network key).

2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.uart] Connection made
2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.api] at command: AP (2,)
2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'AP', b'\x02')
2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x01AP\x02'
2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x01AP\x00'
2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.api] at command: MY ()
2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'MY', b'')
2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x02MY'
2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x02MY\x00\x00\x00'
2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.api] at command: SH ()
2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'SH', b'')
2022-06-08 22:30:41 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x03SH'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x03SH\x00\x00\x13\xa2\x00'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] at command: SL ()
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'SL', b'')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x04SL'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x04SL\x00A\xa0n`'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] at command: CE ()
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'CE', b'')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x05CE'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x05CE\x00\x01'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] at command: OI ()
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'OI', b'')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x06OI'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x06OI\x00\xdd\x94'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] at command: ID ()
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'ID', b'')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x07ID'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x07ID\x00%\xdc\xf8~\x03\xeaY\x06'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] at command: CH ()
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'CH', b'')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x08CH'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x08CH\x00\x0f'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy.application] Network info: NetworkInfo(extended_pan_id=2728328694394935558, pan_id=56724, nwk_update_id=0, nwk_manager_id=0x0000, channel=15, channel_mask=<Channels.NO_CHANNELS: 0>, security_level=0, network_key=Key(key=ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff, tx_counter=0, rx_counter=0, seq=0, partner_ieee=ff:ff:ff:ff:ff:ff:ff:ff), tc_link_key=Key(key=5a:69:67:42:65:65:41:6c:6c:69:61:6e:63:65:30:39, tx_counter=0, rx_counter=0, seq=0, partner_ieee=ff:ff:ff:ff:ff:ff:ff:ff), key_table=[], children=[], nwk_addresses={}, stack_specific={}, metadata={}, source='zigpy-xbee@0.15.0.dev0')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy.application] Node info: NodeInfo(nwk=0x0000, ieee=00:13:a2:00:41:a0:6e:60, logical_type=<LogicalType.Coordinator: 0>)
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] at command: AI ()
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'AI', b'')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\tAI'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\tAI\x00\x00'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] at command: AO (3,)
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'AO', b'\x03')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\nAO\x03'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\nAO\x00'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] at command: EE ()
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'EE', b'')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x0bEE'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x0bEE\x00\x01'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] at command: EO ()
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'EO', b'')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x0cEO'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x0cEO\x00\x02'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] at command: ZS ()
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'ZS', b'')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\rZS'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\rZS\x00\x02'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] at command: NJ (0,)
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'NJ', b'\x00')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x0eNJ\x00'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x0eNJ\x00'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] at command: SP (768,)
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'SP', b'\x03\x00')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x0fSP\x03\x00'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x0fSP\x00'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] at command: SN (667,)
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'SN', b'\x02\x9b')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x10SN\x02\x9b'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x10SN\x00'
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.zigbee.application] Broadcast request seq 1
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.api] Command tx_explicit (00:00:00:00:00:00:ff:fc, <BroadcastAddress.ALL_ROUTERS_AND_COORDINATOR: 65532>, 0, 0, <ZDOCmd.Mgmt_Permit_Joining_req: 0x0036>, 0, 0, 0, b'\x01\x00\x00')
2022-06-08 22:30:42 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x11\x11\x00\x00\x00\x00\x00\x00\xff\xfc\xff\xfc\x00\x00\x006\x00\x00\x00\x00\x01\x00\x00'
2022-06-08 22:30:42 DEBUG (Thread-3) [aiosqlite] executing functools.partial(<built-in method execute of sqlite3.Connection object at 0xb16b8f58>, 'INSERT INTO devices_v9 (ieee, nwk, status, last_seen)\n                    VALUES (?, ?, ?, ?)\n                    ON CONFLICT (ieee)\n                    DO UPDATE SET\n                        nwk=excluded.nwk,\n                        status=excluded.status,\n                        last_seen=excluded.last_seen', (00:13:a2:00:41:a0:6e:60, 0x0000, <Status.ENDPOINTS_INIT: 2>, 0.0))
2022-06-08 22:30:42 DEBUG (Thread-3) [aiosqlite] operation functools.partial(<built-in method execute of sqlite3.Connection object at 0xb16b8f58>, 'INSERT INTO devices_v9 (ieee, nwk, status, last_seen)\n                    VALUES (?, ?, ?, ?)\n                    ON CONFLICT (ieee)\n                    DO UPDATE SET\n                        nwk=excluded.nwk,\n                        status=excluded.status,\n                        last_seen=excluded.last_seen', (00:13:a2:00:41:a0:6e:60, 0x0000, <Status.ENDPOINTS_INIT: 2>, 0.0)) completed
2022-06-08 22:30:42 DEBUG (Thread-3) [aiosqlite] executing functools.partial(<built-in method execute of sqlite3.Connection object at 0xb16b8f58>, 'INSERT INTO node_descriptors_v9\n                VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n                    ON CONFLICT (ieee)\n                    DO UPDATE SET\n                logical_type=excluded.logical_type,\n                complex_descriptor_available=excluded.complex_descriptor_available,\n                user_descriptor_available=excluded.user_descriptor_available,\n                reserved=excluded.reserved,\n                aps_flags=excluded.aps_flags,\n                frequency_band=excluded.frequency_band,\n                mac_capability_flags=excluded.mac_capability_flags,\n                manufacturer_code=excluded.manufacturer_code,\n                maximum_buffer_size=excluded.maximum_buffer_size,\n                maximum_incoming_transfer_size=excluded.maximum_incoming_transfer_size,\n                server_mask=excluded.server_mask,\n                maximum_outgoing_transfer_size=excluded.maximum_outgoing_transfer_size,\n                descriptor_capability_field=excluded.descriptor_capability_field', (00:13:a2:00:41:a0:6e:60, <LogicalType.Coordinator: 0>, 0, 0, 0, 0, <FrequencyBand.Freq2400MHz: 8>, <MACCapabilityFlags.AllocateAddress|RxOnWhenIdle|MainsPowered|FullFunctionDevice: 142>, 4126, 82, 255, 11264, 255, <DescriptorCapability.NONE: 0>))
2022-06-08 22:30:42 DEBUG (Thread-3) [aiosqlite] operation functools.partial(<built-in method execute of sqlite3.Connection object at 0xb16b8f58>, 'INSERT INTO node_descriptors_v9\n                VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n                    ON CONFLICT (ieee)\n                    DO UPDATE SET\n                logical_type=excluded.logical_type,\n                complex_descriptor_available=excluded.complex_descriptor_available,\n                user_descriptor_available=excluded.user_descriptor_available,\n                reserved=excluded.reserved,\n                aps_flags=excluded.aps_flags,\n                frequency_band=excluded.frequency_band,\n                mac_capability_flags=excluded.mac_capability_flags,\n                manufacturer_code=excluded.manufacturer_code,\n                maximum_buffer_size=excluded.maximum_buffer_size,\n                maximum_incoming_transfer_size=excluded.maximum_incoming_transfer_size,\n                server_mask=excluded.server_mask,\n                maximum_outgoing_transfer_size=excluded.maximum_outgoing_transfer_size,\n                descriptor_capability_field=excluded.descriptor_capability_field', (00:13:a2:00:41:a0:6e:60, <LogicalType.Coordinator: 0>, 0, 0, 0, 0, <FrequencyBand.Freq2400MHz: 8>, <MACCapabilityFlags.AllocateAddress|RxOnWhenIdle|MainsPowered|FullFunctionDevice: 142>, 4126, 82, 255, 11264, 255, <DescriptorCapability.NONE: 0>)) completed
2022-06-08 22:30:42 DEBUG (Thread-3) [aiosqlite] executing functools.partial(<built-in method commit of sqlite3.Connection object at 0xb16b8f58>)
2022-06-08 22:30:42 DEBUG (Thread-3) [aiosqlite] operation functools.partial(<built-in method commit of sqlite3.Connection object at 0xb16b8f58>) completed
2022-06-08 22:30:42 DEBUG (MainThread) [homeassistant.bootstrap] Running timeout Zones: {}
2022-06-08 22:30:42 DEBUG (MainThread) [homeassistant.bootstrap] Integration remaining: {'zha': 8.629417}
2022-06-08 22:30:43 DEBUG (MainThread) [homeassistant.bootstrap] Running timeout Zones: {}
2022-06-08 22:30:43 DEBUG (MainThread) [homeassistant.bootstrap] Integration remaining: {'zha': 9.630882}
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x8b\x11\xff\xfe\x00\x00\x00'
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.api] Frame received: tx_status
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.api] tx_explicit to 0xfffe: TXStatus.SUCCESS after 0 tries. Discovery Status: DiscoveryStatus.SUCCESS, Frame #17
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.api] at command: NJ (0,)
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'NJ', b'\x00')
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x12NJ\x00'
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x12NJ\x00'
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.api] at command: AC ()
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'AC', b'')
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x13AC'
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x13AC\x00'
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.api] at command: CB (2,)
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'CB', b'\x02')
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x14CB\x02'
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x8aC'
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.api] Frame received: modem_status
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.api] Handle modem status frame: ModemStatus.JOIN_WINDOW_OPENED
2022-06-08 22:30:43 INFO (MainThread) [zigpy_xbee.zigbee.application] Modem status update: JOIN_WINDOW_OPENED (67)
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x14CB\x00'
2022-06-08 22:30:43 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response

For comparison, here is the startup sequence for the core code (also looks shorter):

2022-06-08 22:53:43 DEBUG (MainThread) [zigpy_xbee.uart] Connection made
2022-06-08 22:53:43 DEBUG (MainThread) [zigpy_xbee.api] at command: AP (2,)
2022-06-08 22:53:43 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'AP', b'\x02')
2022-06-08 22:53:43 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x01AP\x02'
2022-06-08 22:53:43 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x01AP\x00'
2022-06-08 22:53:43 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:43 DEBUG (MainThread) [zigpy_xbee.api] at command: AO (3,)
2022-06-08 22:53:43 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'AO', b'\x03')
2022-06-08 22:53:43 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x02AO\x03'
2022-06-08 22:53:43 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x02AO\x00'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: SH ()
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'SH', b'')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x03SH'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x03SH\x00\x00\x13\xa2\x00'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: SL ()
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'SL', b'')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x04SL'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x04SL\x00A\xa0n`'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.zigbee.application] Read local IEEE address as 00:13:a2:00:41:a0:6e:60
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: AI ()
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'AI', b'')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x05AI'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x05AI\x00\x00'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: MY ()
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'MY', b'')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x06MY'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x06MY\x00\x00\x00'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: EE ()
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'EE', b'')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x07EE'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x07EE\x00\x01'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: EO ()
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'EO', b'')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x08EO'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x08EO\x00\x02'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: ZS ()
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'ZS', b'')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\tZS'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\tZS\x00\x02'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: NJ (0,)
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'NJ', b'\x00')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\nNJ\x00'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\nNJ\x00'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: SP (768,)
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'SP', b'\x03\x00')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x0bSP\x03\x00'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x0bSP\x00'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: SN (667,)
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'SN', b'\x02\x9b')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x0cSN\x02\x9b'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x0cSN\x00'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: ID ()
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'ID', b'')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\rID'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\rID\x00%\xdc\xf8~\x03\xeaY\x06'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.zigbee.application] Extended PAN ID: 0x25dcf87e03ea5906
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: OP ()
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'OP', b'')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x0eOP'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x0eOP\x00%\xdc\xf8~\x03\xeaY\x06'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.zigbee.application] Operating Extended PAN ID: 0x25dcf87e03ea5906
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: OI ()
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'OI', b'')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x0fOI'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x0fOI\x00\xdd\x94'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.zigbee.application] PAN ID: 0xdd94
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] at command: CE ()
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'CE', b'')
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x10CE'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x10CE\x00\x01'
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2022-06-08 22:53:44 DEBUG (MainThread) [zigpy_xbee.zigbee.application] Coordinator enabled

@puddly
Copy link
Contributor Author

puddly commented Jun 8, 2022

Thanks for the feedback, I appreciate it!

You're totally right about the joins. Zigpy now calls ControllerApplication.permit(0) on startup to disable joins but it seems like the implementation in zigpy-xbee does not actually disable joins when 0 is passed as the duration and instead permits joins for 60 seconds:

If NJ is 0x00 or 0xFF, PermitDuration is set to one minute, otherwise PermitDuration is set to NJ.

Is there a way to disable joins without having to enable them for one second?

@Shulyaka
Copy link
Contributor

Shulyaka commented Jun 8, 2022

It is disabling joins by calling NJ0. Twice, actually (!). But later it calls CB2 (Commissioning Pushbutton) which basically enables joins back.
So what we need is to eliminate the CB2 command.

@puddly
Copy link
Contributor Author

puddly commented Jun 8, 2022

Like this?

     async def permit_ncp(self, time_s=60):
         assert 0 <= time_s <= 254
         await self._api._at_command("NJ", time_s)
         await self._api._at_command("AC")
-        await self._api._at_command("CB", 2)
+
+        if time_s > 0:
+            await self._api._at_command("CB", 2)

@Shulyaka
Copy link
Contributor

Shulyaka commented Jun 9, 2022

Just remove the CB, just setting NJ with AC is enough if I am reading the manual correctly:

The following actions restart the permit-joining timer:

  • Changing NJ to a different value (and applying changes with the AC or CN commands).
  • Pressing the Commissioning button twice.
  • Issuing the CB command with a parameter of 2.

So we only need one of the 3.

@puddly puddly marked this pull request as ready for review June 20, 2022 18:33
@puddly puddly merged commit 4ccb5ae into zigpy:dev Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
New radio API
In progress
Development

Successfully merging this pull request may close these issues.

None yet

2 participants