Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
Release 0.40.12
Browse files Browse the repository at this point in the history
  • Loading branch information
doudz committed Jan 12, 2021
2 parents 3029b52 + 21874c6 commit f42fbad
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 17 deletions.
12 changes: 6 additions & 6 deletions tests/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'})

Expand Down Expand Up @@ -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())
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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',
Expand Down
5 changes: 3 additions & 2 deletions zigate/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@
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()
if args.debug:
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:
Expand Down
6 changes: 3 additions & 3 deletions zigate/adminpanel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions zigate/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@
BASE_PATH = os.path.dirname(__file__)

ADMINPANEL_PORT = 9998
ADMINPANEL_HOST = "0.0.0.0"

23 changes: 18 additions & 5 deletions zigate/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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']

Expand Down
58 changes: 58 additions & 0 deletions zigate/templates/TH01.json
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 1 addition & 1 deletion zigate/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#


__version__ = '0.40.11'
__version__ = '0.40.12'

0 comments on commit f42fbad

Please sign in to comment.