-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Added a Taps Aff binary sensor #7880
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
Changes from 1 commit
e1e9d92
f671649
6ddd0c2
7a9bfdf
3f2372d
56384ee
8905827
4c5a882
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| """ | ||
| Support for Taps Aff binary sensor. | ||
|
|
||
| For more details about this platform, please refer to the documentation at | ||
| https://home-assistant.io/components/binary_sensor.tapsaff/ | ||
| """ | ||
| from datetime import timedelta | ||
| import logging | ||
|
|
||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.components.binary_sensor \ | ||
| import (BinarySensorDevice, PLATFORM_SCHEMA) | ||
| from homeassistant.const import (CONF_NAME) | ||
| import homeassistant.helpers.config_validation as cv | ||
| from homeassistant.util import Throttle | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed when going with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've moved to |
||
|
|
||
| REQUIREMENTS = ['tapsaff==0.1.0'] | ||
|
|
||
| CONF_LOCATION = "location" | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| DEFAULT_NAME = 'Taps Aff' | ||
|
|
||
| MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=30) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
|
|
||
| PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
| vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, | ||
| vol.Required(CONF_LOCATION): cv.string, | ||
| }) | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_devices, discovery_info=None): | ||
| """Set up the taps aff sensor.""" | ||
| name = config.get(CONF_NAME) | ||
| location = config.get(CONF_LOCATION) | ||
|
|
||
| taps_aff_data = TapsAffData(location) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess that there will be an exception if the location is not available. For users it will be helpful if there is a log entry that indicate this. Make the setup return if the location is not present this will ensure that the users are not having a non-functional platform for their instance.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An exception is thrown, but I've improved the base library as I found a case where an exception slipped through. I've caught |
||
|
|
||
| add_devices([TapsAffSensor(taps_aff_data, name)], True) | ||
|
|
||
|
|
||
| class TapsAffSensor(BinarySensorDevice): | ||
| """Implementation of a taps aff sensor.""" | ||
|
|
||
| def __init__(self, taps_aff_data, name): | ||
| """Initialize the sensor.""" | ||
| self.data = taps_aff_data | ||
| self._name = name | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the name of the sensor.""" | ||
| return '{}'.format(self._name) | ||
|
|
||
| @property | ||
| def is_on(self): | ||
| """Return true if taps aff.""" | ||
| return self.data.is_taps_aff | ||
|
|
||
| def update(self): | ||
| """Get the latest data.""" | ||
| self.data.update() | ||
|
|
||
|
|
||
| class TapsAffData(object): | ||
| """Class for handling the data retrieval for pins.""" | ||
|
|
||
| def __init__(self, location): | ||
| """Initialize the sensor.""" | ||
| from tapsaff import TapsAff | ||
|
|
||
| self._is_taps_aff = None | ||
| self.taps_aff = TapsAff(location) | ||
|
|
||
| @property | ||
| def is_taps_aff(self): | ||
| """Return true if taps aff.""" | ||
| return self._is_taps_aff | ||
|
|
||
| @Throttle(MIN_TIME_BETWEEN_UPDATES) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed when going with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
| def update(self): | ||
| """Get the latest data from the Taps Aff API and updates the states.""" | ||
| self._is_taps_aff = self.taps_aff.is_taps_aff | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
\is not needed if the line break is moved.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed