Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #26 from zha-ng/rc
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
Adminiuga authored Sep 21, 2020
2 parents fab6fde + b387844 commit fcad4a7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 56 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ Zigbee network mapping with zha-map can help you identify weak points like bad l
- https://github.com/zha-ng/zha-map
2. Add zha_map: to your configuration.yaml and restart Home Assistant
3. Wait for a scan to complete (logs to DEBUG, or use the new zha_map service to scan on demand)
4. Install the zha-network-visualization-card lovelace card
4. Install one of the visualization cards:
- https://github.com/dmulcahey/zha-network-visualization-card
- https://github.com/Samantha-uk/zigzag
5. Add to your lovelace global config as type: module
6. Add custom card (works best in panel mode): - type: 'custom:zha-network-visualization-card'

Expand Down
66 changes: 12 additions & 54 deletions custom_components/zha_map/neighbour.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,6 @@ class NeighbourType(enum.IntEnum):
Unknown = 0x3


class RxOnIdle(enum.IntEnum):
Off = 0x0
On = 0x1
Unknown = 0x2


class Relation(enum.IntEnum):
Parent = 0x0
Child = 0x1
Sibling = 0x2
None_of_the_above = 0x3
Previous_Child = 0x4


class PermitJoins(enum.IntEnum):
Not_Accepting = 0x0
Accepting = 0x1
Unknown = 0x2


@attr.s
class Neighbour(LogMixin):
ieee = attr.ib(default=None)
Expand All @@ -64,35 +44,15 @@ def new_from_record(cls, record):

r = cls()
r.offline = False
r.pan_id = str(record.PanId)
r.ieee = record.IEEEAddr

raw = record.NeighborType & 0x03
try:
r.device_type = NeighbourType(raw).name
except ValueError:
r.device_type = "undefined_0x{:02x}".format(raw)

raw = (record.NeighborType >> 2) & 0x03
try:
r.rx_on_when_idle = RxOnIdle(raw).name
except ValueError:
r.rx_on_when_idle = "undefined_0x{:02x}".format(raw)

raw = (record.NeighborType >> 4) & 0x07
try:
r.relation = Relation(raw).name
except ValueError:
r.relation = "undefined_0x{:02x}".format(raw)

raw = record.PermitJoining & 0x02
try:
r.new_joins_accepted = PermitJoins(raw).name
except ValueError:
r.new_joins_accepted = "undefined_0x{:02x}".format(raw)

r.depth = record.Depth
r.lqi = record.LQI
r.pan_id = str(record.extended_pan_id)
r.ieee = record.ieee

r.device_type = record.struct.device_type.name
r.rx_on_when_idle = record.struct.rx_on_when_idle.name
r.relation = record.struct.relationship.name
r.new_joins_accepted = record.permit_joining.name
r.depth = record.depth
r.lqi = record.lqi
return r

def _update_info(self):
Expand All @@ -119,16 +79,14 @@ async def scan(self):
"""Scan for neighbours."""
idx = 0
while True:
status, val = await self.device.zdo.request(
zdo_t.ZDOCmd.Mgmt_Lqi_req, idx, tries=3, delay=1
)
status, val = await self.device.zdo.Mgmt_Lqi_req(idx, tries=3, delay=1)
self.debug("neighbor request Status: %s. Response: %r", status, val)
if zdo_t.Status.SUCCESS != status:
self.supported = False
self.debug("device does not support 'Mgmt_Lqi_req'")
return

neighbors = val.NeighborTableList
neighbors = val.neighbor_table_list
for neighbor in neighbors:
new = self.new_from_record(neighbor)

Expand All @@ -147,7 +105,7 @@ async def scan(self):
self.warning("neighbour %s is not in 'zigbee.db'", new.ieee)
self.neighbours.append(new)
idx += 1
if idx >= val.Entries:
if idx >= val.entries:
break
if len(neighbors) <= 0:
idx += 1
Expand Down
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![GitHub Release][releases-shield]][releases]
[![License][license-shield]](LICENSE.md)
[![License][license-shield]](LICENSE)
[![Discord][discord-shield]][discord]

**ZHA integration: create a map of all ZHA devices.**
Expand Down

0 comments on commit fcad4a7

Please sign in to comment.