Skip to content

Commit 95e88ce

Browse files
authored
Merge pull request #44 from WayneManion/master
Added the ability to auto configure hidraw device
2 parents 146938b + cb84cf8 commit 95e88ce

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

custom_components/wyzesense/binary_sensor.py

100755100644
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99
import voluptuous as vol
1010
from retry import retry
11+
import subprocess
1112

1213
from homeassistant.const import CONF_FILENAME, CONF_DEVICE, \
1314
EVENT_HOMEASSISTANT_STOP, STATE_ON, STATE_OFF, ATTR_BATTERY_LEVEL, \
@@ -28,7 +29,7 @@
2829
CONF_INITIAL_STATE = "initial_state"
2930

3031
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
31-
vol.Required(CONF_DEVICE): cv.string,
32+
vol.Optional(CONF_DEVICE, default = "auto"): cv.string,
3233
vol.Optional(CONF_INITIAL_STATE, default={}): vol.Schema({cv.string : vol.In(["on","off"])})
3334
})
3435

@@ -43,9 +44,17 @@
4344

4445
_LOGGER = logging.getLogger(__name__)
4546

47+
def findDongle():
48+
df = subprocess.check_output(["ls", "-la", "/sys/class/hidraw"]).decode('utf-8').lower()
49+
for l in df.split('\n'):
50+
if ("e024" in l and "1a86" in l):
51+
for w in l.split(' '):
52+
if ("hidraw" in w):
53+
return "/dev/%s" % w
4654

4755
def setup_platform(hass, config, add_entites, discovery_info=None):
48-
56+
if config[CONF_DEVICE].lower() == 'auto':
57+
config[CONF_DEVICE] = findDongle()
4958
_LOGGER.debug("WYZESENSE v0.0.4")
5059
_LOGGER.debug("Attempting to open connection to hub at " + config[CONF_DEVICE])
5160

0 commit comments

Comments
 (0)