8000 Netatmo binary sensor by jabesq · Pull Request #3455 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Netatmo binary sensor #3455

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

Merged
merged 5 commits into from
Oct 9, 2016
Merged

Netatmo binary sensor #3455

merged 5 commits into from
Oct 9, 2016

Conversation

jabesq
Copy link
Contributor
@jabesq jabesq commented Sep 19, 2016

Description:
This PR create a new platform which provides binary sensor based on event seen by the Netatmo camera

Related issue (if applicable): fixes #

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#964

Example entry for configuration.yaml (if applicable):

binary_sensor:
   platform: netatmo
   home: home_name
   cameras:
     - camera_name1
     - camera_name2
   monitored_conditions:
     - Someone known
     - Someone unknown 
     - Motion

Checklist:

If user exposed functionality or configuration variables are added/changed:

If code communicates with devices, web services, or a:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

return self._name

@property
def unique_id(self):
Copy link
Member

Choose a reason for hiding this comment

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

Remove that. The HA core do that same and is more robust.

Copy link
Member

Choose a reason for hiding this comment

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

Nah, if a platform implements it it will be better. They know exactly which is unique. However, a name is not very unique? Do you have access to a serial?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the netatmo api provides an unique ID for each camera/device

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change Done

return self._name

@property
def unique_id(self):
Copy link
Member

Choose a reason for hiding this comment

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

Nah, if a platform implements it it will be better. They know exactly which is unique. However, a name is not very unique? Do you have access to a serial?

@@ -50,7 +49,4 @@ def setup(hass, config):
_LOGGER.error("Unable to connect to NatAtmo API")
return False

for component in 'camera', 'sensor':
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove discovery ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was creating issue as some person can have the weather station but does not have the camera, or they could have multiple camera and displaying only one.

My original goal was to use the discovery if no camera was settup but if one was setup, then do not use the discovery, but currently it did not work well as two feed of the same camera could be displayed

Copy link
Member

Choose a reason for hiding this comment

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

Other platforms fix this by checking the data to see if there is a camera, sensor etc.

I want to keep the discovery in because it is helps users get started. If the camera component will only setup 1 camera, then that is also that has to be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No the camera component can setup as many camera as you want, but the thing is that might don't want to have all the information from the camera, for instance, the binary sensor create 3 sensor by camera by default, bu user might don't want to have the 'Someone known' sensor if they have a more precise device tracker (moreover with my next update which should implement presence detection based on the Netatmo camera).

I would me more than happy to use the discovery, but discovery use the default config (all camera, all sensors) but if I setup a specific config it creates duplicate in the interface (the feed from discovery and the one from specific setup)

Copy link
Member

Choose a reason for hiding this comment

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

Make it configurable but default it to on as automatic setup of platforms helps new users get started.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok do you have example that I can copy

return None


class WelcomeData(object):
Copy link
Member

Choose a reason for hiding this comment

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

This is a direct copy of the one in camera ? Why not make it a generic object, instantiated once in the main component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You 're right and as this code will also be use for the coming presence detection platform, it make more sense to put inside components/netatmo.py

@rofrantz
Copy link 8000
Contributor

You can use two aproches in order to use discovery:

  1. automatic capability: check whether the discovered device has any capability reported
    Or
  2. manual capability detection: test them youself in the code to see if u have a camera, wheather or anything other capability

The last one could be done in the netdisco ant it would emit in your case only two entities discovered and then in HA two different components would listen for them and render them in the frontend

@jabesq
Copy link
Contributor Author
jabesq commented Sep 20, 2016

@rofrantz I used the second approach but it was not perfect as the Netatmo API will return all the devices that you own, but if you have one camera in one home and an another one in another home you might don't want to display both in you home-assistant interface.

My idea was to use the discovery if no specific camera has been setup in the configuration.yaml (then it will use the default camera), but if a camera is setup then discovery is ignored.

@rofrantz
Copy link
Contributor

Still sounds like a custom setup meaning that u have 2 cameras in 2 different locations in the same HA instance; why dont u hide one of two entities if thats the issue or add a default camera flag.
Although as I read this again indeed its a custom setup with a delicate solution which would only complica the HA logic, so yeah we better drop it :)

@jabesq
Copy link
Contributor Author
jabesq commented Sep 26, 2016

This PR also fixes an issue with voluptuous that will be introduce by #3287 in release 0.29 #3486

@@ -50,7 +49,7 @@
}

MODULE_SCHEMA = vol.Schema({
vol.Required(CONF_MODULE_NAME, default=[]):
vol.Required(cv.string, default=[]):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix for #3287

Copy link
Member

Choose a reason for hiding this comment

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

Because this fix was bundled with a PR for a feature, I have missed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I'm preparing another PR for this fix solely

@jabesq jabesq force-pushed the Netatmo-BinSensor branch 3 times, most recently from 715d7d7 to cd354a7 Compare September 30, 2016 13:26
if config[CONF_CAMERAS] != []:
if camera_name not in config[CONF_CAMERAS]:
continue
if CONF_CAMERAS in config:
Copy link
Member

Choose a reason for hiding this comment

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

Can you simplify this by moving it outside of the loop (it won't change during the loop) and also convert to be 1 if statement.

@@ -50,7 +49,4 @@ def setup(hass, config):
_LOGGER.error("Unable to connect to NatAtmo API")
return False

for component in 'camera', 'sensor':
Copy link
Member

Choose a reason for hiding this comment

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

Make it configurable but default it to on as automatic setup of platforms helps new users get started.

sensors = config.get(CONF_MONITORED_CONDITIONS, SENSOR_TYPES)

for camera_name in data.get_camera_names():
if config[CONF_CAMERAS] != []:
Copy link
Member
@balloob balloob Sep 30, 2016

Choose a reason for hiding this comment

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

Can you simplify this by moving it outside of the loop (it won't change during the loop) and also convert to be 1 if statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is difficult to simplify as this solution allows me to have only one for loop instead of two

jabesq added 5 commits October 2, 2016 15:04
Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>
Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>
Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>
And global config to disable discovery for netatmo devices

Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>
@jabesq jabesq force-pushed the Netatmo-BinSensor branch from cd354a7 to 8c602f3 Compare October 2, 2016 13:11
@balloob
Copy link
Member
balloob commented Oct 9, 2016

🐬

@balloob balloob merged commit 1d0df63 into home-assistant:dev Oct 9, 2016
@jabesq jabesq deleted the Netatmo-BinSensor branch October 18, 2016 16:40
@home-assistant home-assistant locked and limited conversation to collaborators Mar 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0