Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to auto configure hidraw device #44

Merged
merged 2 commits into from
Nov 24, 2019

Conversation

WayneManion
Copy link

@WayneManion WayneManion commented Oct 15, 2019

Enter the following config data for wyzesense:

- platform: wyzesense
  device: auto

The custom_component will use the contents of /sys/class/hidraw to determine which hidraw device is the Wyze receiver dongle and then use that info to initialize the dongle.

@WayneManion
Copy link
Author

Also, there are bunch of spots in 0.0.5 that say '0.0.4' in the debug logs. I didn't fix those, but they're present.

@ammmze
Copy link

ammmze commented Oct 16, 2019

Nice ... This will remove my need to add a custom udev rule. I keep having issues where the device path changes. Sometimes it /dev/hidraw0, then later it's /dev/hidraw3. So as long as my device paths aren't changing while home assistant is running, then I should be good. I don't know for sure if its changing when I reboot the server or when it is actually changing.

But this is the workaround I'm currently testing...

On the host run:

echo 'SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="e024", SYMLINK+="wyze"' | sudo tee /etc/udev/rules.d/99-wyze.rules > /dev/null \
    && sudo udevadm control --reload \
    && sudo udevadm trigger

Then the device should be available at /dev/wyze...which technically is a symlink to /dev/hidraw0 (or whatever it got mounted as). Not a perfect solution as you'd have to make sure /dev/wyze and all the /dev/hidrawX devices are mounted in the docker container. But most installations are probably mounting all of them anyways.

@WayneManion
Copy link
Author

WayneManion commented Oct 16, 2019

I was doing something similar, but hass.io (which I run in Docker on an Intel machine) completely ignores any symlinks you set up.

It's probably possible to change the component so that the "device: auto" isn't needed in configuration.yaml, but I don't know enough about the custom_component architecture to make that work correctly.

I know for a fact my code won't run on a Windows install, but I don't think this component ran on Windows to start with.

@ammmze
Copy link

ammmze commented Oct 16, 2019

Good to know ... I may run into the same thing then ... i haven't actually switched over to /dev/wyze yet. So far just got it to where it was creating the symlink.

Edit: Sure enough ... looks like docker is not passing through the symlinked device 😞 ... so hopefully this gets picked up soon-ish 😀

@ammmze
Copy link

ammmze commented Oct 17, 2019

FWIW, i've just uninstalled my existing ha-wyzesense and installed the one from this PR and so far so good 👍

I'm running Hass.io via Docker on a Ubuntu 18.04.3 server

Copy link

@ammmze ammmze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we make it auto by default by updating this line...

from:

vol.Required(CONF_DEVICE): cv.string,

to

vol.Optional(CONF_DEVICE, default="auto"): cv.string,

Copy link

@ammmze ammmze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had some nit picky comments, but I think these changes should be good. Though to be fair I've only really dealt with ubuntu servers, so can't really speak to how that ls -la /sys/class/hidraw comes through in other servers.

def findDongle(): # wmm
df = subprocess.check_output(["ls", "-la", "/sys/class/hidraw"]).decode('utf-8')
for l in df.split('\n'):
if ("e024" in l and "1a86" in l) or ("E024" in l and "1A86" in l):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be better to do something like:

ll = l.lower()
if ("e024" in ll and "1a86" in ll):

This way take out 2 extra searches in each string plus reduces the chance that someone updates one set, but not the other.


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

if config[CONF_DEVICE] == 'auto': #wmm
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this ignore case too? Sorry ... nit picking here 😀

if config[CONF_DEVICE].lower() == 'auto'

Made changes less sensitive to inconsistencies in capitalization.
@WayneManion
Copy link
Author

Those are quality suggestions ammmze. I had tried changing that vol.Required line to vol.Optional before, but I did not know to add the ', default = "auto"' part. I tested these changes and they worked for me.

Copy link

@ammmze ammmze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 👍 great work

@Nighteyez07
Copy link

This PR has been completed for a month, is there any plan to implement this into Master? The ability to auto detect the proper hidraw device would prevent a lot of headache.

@blaster452
Copy link

I can confirm this has fixed my problem of hidraw number change on reboot. The change works for me on a linux system runinng on a NUC. Thanks for the help!

@kevinvincent kevinvincent merged commit 95e88ce into kevinvincent:master Nov 24, 2019
@kevinvincent
Copy link
Owner

Sorry all, I've been totally away from the project trying to finish up my undergrad. I'm adding another community member as a maintainer for now until I can get back on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants