Skip to content

Commit

Permalink
Merge pull request smarthomeNG#867 from Morg42/develop
Browse files Browse the repository at this point in the history
zigbee2mqtt: small changes and fixes
  • Loading branch information
Morg42 authored Dec 18, 2023
2 parents 80d9143 + 0d07d47 commit 7a615a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
31 changes: 19 additions & 12 deletions zigbee2mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ def __init__(self, sh, **kwargs):
self.z2m_base = self.get_parameter_value('base_topic').lower()
self.cycle = self.get_parameter_value('poll_period')
self.read_at_init = self.get_parameter_value('read_at_init')
self.bool_values = self.get_parameter_value('bool_values')
self._z2m_gui = self.get_parameter_value('z2m_gui')

# bool_values is only good if used internally, because MQTT data is
# usually sent in JSON. So just make this easy...
self.bool_values = [False, True]

self._items_read = []
self._items_write = []
self._devices = {'bridge': {}}
Expand All @@ -88,17 +91,17 @@ def __init__(self, sh, **kwargs):

# Add subscription to get bridge announces
bridge_subs = [
['devices', 'list', None],
['state', 'dict', None],
['info', 'dict', None],
['log', 'dict', None],
['extensions', 'list', None],
['config', 'dict', None],
['groups', 'list', None],
['response', 'dict', None]
['devices', 'list'],
['state', 'str'],
['info', 'dict'],
['log', 'dict'],
['extensions', 'list'],
['config', 'dict'],
['groups', 'list'],
['response', 'dict']
]
for attr, dtype, blist in bridge_subs:
self.add_z2m_subscription('bridge', attr, '', '', dtype, callback=self.on_mqtt_msg, bool_values=blist)
for attr, dtype in bridge_subs:
self.add_z2m_subscription('bridge', attr, '', '', dtype, callback=self.on_mqtt_msg)

# Add subscription to get device announces
self.add_z2m_subscription('+', '', '', '', 'dict', callback=self.on_mqtt_msg)
Expand Down Expand Up @@ -526,7 +529,11 @@ def _handle_in_dev_bridge(self, device: str, topic_3: str = "", topic_4: str = "
_bridge = self._devices[device]

if topic_3 == 'state':
return {'online': bool(['offline', 'online'].index(payload.get(topic_3)))}
try:
data = json.loads(payload)
except json.JSONDecodeError:
data = {'state': payload}
return {'online': bool(['offline', 'online'].index(data.get(topic_3)))}

elif topic_3 in ('config', 'info'):
assert isinstance(payload, dict), 'dict'
Expand Down
17 changes: 5 additions & 12 deletions zigbee2mqtt/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,12 @@ parameters:
de: Pfad zum Suspend-Item
en: Path to suspend item

bool_values:
type: list
default: ['OFF', 'ON']
description:
de: Plugin-weite Ersetzungwerte für bool-Werte
en: Plugin-wide substitution values for bool items

z2m_gui:
type: str
default: ''
default: 'localhost:8080'
description:
de: Host:Port des zigbee2mqtt-Web-GUI
en: host:port of the zigbee2mqtt-web-GUI
de: Web-Adresse des zigbee2mqtt-Web-GUI (Standard localhost:8080)
en: Web address of the zigbee2mqtt-web-GUI (default localhost:8080)

item_attributes:
# Definition of item attributes defined by this plugin (enter 'item_attributes: NONE', if section should be empty)
Expand Down Expand Up @@ -95,8 +88,8 @@ item_attributes:
z2m_bool_values:
type: list
description:
de: Ersetzungwerte für bool-Werte
en: substitution values for bool items
de: Ersetzungwerte für bool-Werte (z.B. ['OFF', 'ON'])
en: substitution values for bool items (e.g. ['OFF', 'ON'])


item_structs:
Expand Down
2 changes: 2 additions & 0 deletions zigbee2mqtt/webif/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
<table id="itemtable" class="table_1 table-striped table-hover pluginList display">
<thead>
<tr>
<th></th>
<th>{{ _('Item') }}</th>
<th>{{ _('Typ') }}</th>
<th style="text-align: right">{{ _('Wert') }}</th>
Expand All @@ -205,6 +206,7 @@
{% for item in items %}
{% set item_id = item.id() %}
<tr>
<td class="py-1"></td>
<td class="py-1">{{ item.property.path }}</td>
<td class="py-1">{{ item.property.type }}</td>
<td class="py-1" id="{{ item_id }}_value" style="text-align: right">{{ item()}}</td>
Expand Down

0 comments on commit 7a615a5

Please sign in to comment.