diff --git a/tests/test_devices.py b/tests/test_devices.py index 5bccdc04..b02cc8b2 100644 --- a/tests/test_devices.py +++ b/tests/test_devices.py @@ -46,12 +46,12 @@ def test_device_dump(self): '"lqi": 255}, "name": "sample"}')) def test_template(self): - device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}) + device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}, self.zigate) device.set_attribute(1, 0, {'attribute': 5, 'lqi': 255, 'data': 'lumi.test'}) self.assertFalse(device.load_template()) self.assertNotEqual(device.discovery, 'templated') - device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}) + device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}, self.zigate) self.assertFalse(device.load_template()) device.set_attribute(1, 0, {'attribute': 5, 'lqi': 255, 'data': 'lumi.weather'}) @@ -106,7 +106,7 @@ def test_template(self): 'name': ''} ) # another test - device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}) + device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}, self.zigate) self.assertFalse(device.load_template()) device.set_attribute(1, 0, {'attribute': 5, 'lqi': 255, 'data': 'lumi.sensor_wleak.aq1'}) self.assertTrue(device.load_template()) @@ -118,7 +118,7 @@ def test_template(self): 'test_mode': False, 'battery_defect': False} ) - device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}) + device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}, self.zigate) device.set_attribute(1, 0, {'attribute': 5, 'lqi': 255, 'data': 'lumi.sensor_cube'}) self.assertEqual(device.discovery, 'templated') self.assertCountEqual(device.attributes, @@ -136,7 +136,7 @@ def test_template(self): 'value': 0.0, 'unit': '°', 'expire': 2, 'type': float}] ) - device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}) + device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}, self.zigate) device.set_attribute(1, 0, {'attribute': 5, 'lqi': 255, 'data': 'lumi.remote.b186acn01'}) self.assertTrue(device.load_template()) self.assertCountEqual(device.attributes, @@ -148,7 +148,7 @@ def test_template(self): 'value': '', 'expire': 2, 'type': str}] ) - device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}) + device = core.Device({'addr': '1234', 'ieee': '0123456789abcdef'}, self.zigate) device.set_attribute(1, 0, {'attribute': 5, 'lqi': 255, 'data': 'lumi.remote.b286acn01'}) self.assertCountEqual(device.attributes, [{'endpoint': 1, 'cluster': 0, 'attribute': 4, 'data': 'LUMI', diff --git a/zigate/__main__.py b/zigate/__main__.py index cba8dcc9..b3c5ebd8 100644 --- a/zigate/__main__.py +++ b/zigate/__main__.py @@ -24,6 +24,7 @@ parser.add_argument('--channel', help='Zigbee channel', default=None) parser.add_argument('--admin_panel', help='Enable Admin panel', default=True, action='store_true') parser.add_argument('--admin_panel_port', help='Admin panel url prefix', default=9998) +parser.add_argument('--admin_panel_host', help='Admin panel url prefix', default="0.0.0.0") parser.add_argument('--admin_panel_mount', help='Admin panel url mount point', default=None) parser.add_argument('--admin_panel_prefix', help='Admin panel url prefix', default=None) args = parser.parse_args() @@ -31,12 +32,12 @@ logging.root.setLevel(logging.DEBUG) z = connect(args.port, args.host, args.path, True, True, args.channel, args.gpio) if args.admin_panel: - logging.root.info('Starting Admin Panel on port %s', args.admin_panel_port) + logging.root.info('Starting Admin Panel on %s:%s', args.admin_panel_host, args.admin_panel_port) if args.admin_panel_mount: logging.root.info('Mount point is %s', args.admin_panel_mount) if args.admin_panel_prefix: logging.root.info('URL prefix is %s', args.admin_panel_prefix) - z.start_adminpanel(port=int(args.admin_panel_port), mount=args.admin_panel_mount, prefix=args.admin_panel_prefix, + z.start_adminpanel(port=int(args.admin_panel_port), host=args.admin_panel_host, mount=args.admin_panel_mount, prefix=args.admin_panel_prefix, debug=args.debug) print('Press Ctrl+C to quit') try: diff --git a/zigate/adminpanel/__init__.py b/zigate/adminpanel/__init__.py index 36adb24c..ff0337b2 100644 --- a/zigate/adminpanel/__init__.py +++ b/zigate/adminpanel/__init__.py @@ -11,14 +11,14 @@ from json import dumps from zigate import version as zigate_version from zigate.core import DeviceEncoder -from zigate.const import ADMINPANEL_PORT +from zigate.const import ADMINPANEL_PORT, ADMINPANEL_HOST import time bottle.TEMPLATE_PATH.insert(0, os.path.join(os.path.dirname(__file__), 'views/')) -def start_adminpanel(zigate_instance, port=ADMINPANEL_PORT, mount=None, prefix=None, +def start_adminpanel(zigate_instance, host=ADMINPANEL_HOST, port=ADMINPANEL_PORT, mount=None, prefix=None, autostart=True, daemon=True, quiet=True, debug=False): ''' mount: url prefix used to mount bottle application @@ -180,7 +180,7 @@ def network_table(): force = bottle.request.query.get('force', 'false') == 'true' return {'network_table': zigate_instance.build_neighbours_table(force)} - kwargs = {'host': '0.0.0.0', 'port': port, + kwargs = {'host': host, 'port': port, 'quiet': quiet, 'debug': debug} if autostart: diff --git a/zigate/const.py b/zigate/const.py index e1125057..03301cac 100644 --- a/zigate/const.py +++ b/zigate/const.py @@ -88,3 +88,5 @@ BASE_PATH = os.path.dirname(__file__) ADMINPANEL_PORT = 9998 +ADMINPANEL_HOST = "0.0.0.0" + diff --git a/zigate/core.py b/zigate/core.py index e624e04d..654cfd13 100644 --- a/zigate/core.py +++ b/zigate/core.py @@ -284,13 +284,14 @@ def ieee(self): def addr(self): return self._addr - def start_adminpanel(self, port=None, mount=None, prefix=None, debug=False): + def start_adminpanel(self, host=None, port=None, mount=None, prefix=None, debug=False): ''' Start Admin panel in other thread ''' - from .adminpanel import start_adminpanel, ADMINPANEL_PORT + from .adminpanel import start_adminpanel, ADMINPANEL_HOST, ADMINPANEL_PORT port = port or ADMINPANEL_PORT - self.adminpanel = start_adminpanel(self, port=port, mount=mount, prefix=prefix, quiet=not debug, debug=debug) + host = host or ADMINPANEL_HOST + self.adminpanel = start_adminpanel(self, host=host, port=port, mount=mount, prefix=prefix, quiet=not debug, debug=debug) return self.adminpanel def _event_loop(self): @@ -2681,6 +2682,16 @@ def _bind_report(self, enpoint_id=None): if 0x0400 in endpoint['in_clusters']: LOGGER.debug('bind for cluster 0x0400') self._zigate.bind_addr(self.addr, endpoint_id, 0x0400) + if 0x0402 in endpoint['in_clusters']: + LOGGER.debug('bind for cluster 0x0402') + self._zigate.bind_addr(self.addr, endpoint_id, 0x0402) + self._zigate.reporting_request(self.addr, endpoint_id, + 0x0402, (0x0000, 0x29), 0, 0, 30, 3600) + if 0x0405 in endpoint['in_clusters']: + LOGGER.debug('bind for cluster 0x0405') + self._zigate.bind_addr(self.addr, endpoint_id, 0x0405) + self._zigate.reporting_request(self.addr, endpoint_id, + 0x0405, (0x0000, 0x21), 0, 0, 30, 3600) if 0xFC00 in endpoint['in_clusters']: LOGGER.debug('bind for cluster 0xFC00') self._zigate.bind_addr(self.addr, endpoint_id, 0xFC00) @@ -3075,8 +3086,10 @@ def set_attribute(self, endpoint_id, cluster_id, data): **{'zigate': self._zigate, 'device': self, 'attribute': changed}) - - self._handle_quirks(changed) + try: + self._handle_quirks(changed) + except Exception: + LOGGER.exception('Failed handling quirks') return added, attribute['attribute'] diff --git a/zigate/templates/TH01.json b/zigate/templates/TH01.json new file mode 100644 index 00000000..b15add45 --- /dev/null +++ b/zigate/templates/TH01.json @@ -0,0 +1,58 @@ +{ + "endpoints": [ + { + "clusters": [ + { + "attributes": [ + { + "attribute": 4, + "data": "eWeLink" + }, + { + "attribute": 5, + "data": "TH01" + } + ], + "cluster": 0 + }, + { + "attributes": [ + { + "attribute": 0 + } + ], + "cluster": 1026 + }, + { + "attributes": [ + { + "attribute": 0 + } + ], + "cluster": 1029 + } + ], + "device": 770, + "endpoint": 1, + "in_clusters": [ + 0, + 3, + 1026, + 1029 + ], + "out_clusters": [ + 3 + ], + "profile": 260 + } + ], + "generictype": "sensor", + "info": { + "bit_field": "0100000000000010", + "descriptor_capability": "00000000", + "mac_capability": "10000000", + "manufacturer_code": "", + "power_type": 0, + "server_mask": 0 + } +} \ No newline at end of file diff --git a/zigate/version.py b/zigate/version.py index d2e98b61..8112370f 100644 --- a/zigate/version.py +++ b/zigate/version.py @@ -6,4 +6,4 @@ # -__version__ = '0.40.11' +__version__ = '0.40.12'