Skip to content

Commit

Permalink
Merge pull request #44 from WayneManion/master
Browse files Browse the repository at this point in the history
Added the ability to auto configure hidraw device
  • Loading branch information
kevinvincent authored Nov 24, 2019
2 parents 146938b + cb84cf8 commit 95e88ce
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions custom_components/wyzesense/binary_sensor.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import voluptuous as vol
from retry import retry
import subprocess

from homeassistant.const import CONF_FILENAME, CONF_DEVICE, \
EVENT_HOMEASSISTANT_STOP, STATE_ON, STATE_OFF, ATTR_BATTERY_LEVEL, \
Expand All @@ -28,7 +29,7 @@
CONF_INITIAL_STATE = "initial_state"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_DEVICE): cv.string,
vol.Optional(CONF_DEVICE, default = "auto"): cv.string,
vol.Optional(CONF_INITIAL_STATE, default={}): vol.Schema({cv.string : vol.In(["on","off"])})
})

Expand All @@ -43,9 +44,17 @@

_LOGGER = logging.getLogger(__name__)

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

def setup_platform(hass, config, add_entites, discovery_info=None):

if config[CONF_DEVICE].lower() == 'auto':
config[CONF_DEVICE] = findDongle()
_LOGGER.debug("WYZESENSE v0.0.4")
_LOGGER.debug("Attempting to open connection to hub at " + config[CONF_DEVICE])

Expand Down

0 comments on commit 95e88ce

Please sign in to comment.