-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Support binary_sensor and device_tracker for HomeKit #13701
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
Closed
Closed
Changes from 12 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
05041c9
Merge remote-tracking branch 'home-assistant/dev' into dev
aaa5e5f
Support binary_sensor and device_tracker for HomeKit
1e4cd78
Line wrap to 79 chars
af89ce6
Check 'home' for device_tracker for HomeKit
cacf0e5
Refine params/const based on advice:
c72faea
Trim trailing whitespace and align hanging indent
469b7e9
Trim trailing whitespace
a80f739
Revise param/const/device_class_key based on advice
4eb721e
Wrap long line and add a blank line
d10c6cf
Merge remote-tracking branch 'home-assistant/dev' into Yonsm_dev
ef448c7
Merge remote-tracking branch 'home-assistant/dev' into Yonsm_dev
3fe9284
Revise const and coding style
8548761
Update Homekit to 1.1.9 (#13716)
cdce8p 3394916
Update docstrings (#13720)
fabaff 48fe2d1
Add option to ignore availability in google calendar events (#13714)
cgtobi c77d013
Allow use of date_string in service call (#13256)
bjw-s 262ea14
Add timeout / debounce (for brightness and others) (#13534)
cdce8p fdf93d1
added support for smappee water sensors (#12831)
hmn 286476f
Initialise filter_sensor with historical values (#13075)
dgomes 58f3690
Fix Gogogate2 'available' attribute (#13728)
dlbroadfoot 669dbe6
Support binary_sensor and device_tracker for HomeKit
7fa34fe
Line wrap to 79 chars
050d0d9
Check 'home' for device_tracker for HomeKit
44436ce
Refine params/const based on advice:
8af2099
Trim trailing whitespace and align hanging indent
43c5ea7
Trim trailing whitespace
82606ae
Revise param/const/device_class_key based on advice
260a47d
Wrap long line and add a blank line
73cac24
Revise const and coding style
51d8e22
Remove should_callback=False for HAP-python 1.1.9
4e08e1e
Merge remote-tracking branch 'origin/Yonsm_dev' into Yonsm_dev
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,19 +2,45 @@ | |
| import logging | ||
|
|
||
| from homeassistant.const import ( | ||
| ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS) | ||
| ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS, | ||
| ATTR_DEVICE_CLASS, STATE_ON, STATE_HOME) | ||
|
|
||
| from . import TYPES | ||
| from .accessories import HomeAccessory, add_preload_service | ||
| from .const import ( | ||
| CATEGORY_SENSOR, SERV_HUMIDITY_SENSOR, SERV_TEMPERATURE_SENSOR, | ||
| CHAR_CURRENT_HUMIDITY, CHAR_CURRENT_TEMPERATURE, PROP_CELSIUS) | ||
| CHAR_CURRENT_HUMIDITY, CHAR_CURRENT_TEMPERATURE, PROP_CELSIUS, | ||
| DEVICE_CLASS_CO2, SERV_CARBON_DIOXIDE_SENSOR, CHAR_CARBON_DIOXIDE_DETECTED, | ||
| DEVICE_CLASS_GAS, SERV_CARBON_MONOXIDE_SENSOR, | ||
| CHAR_CARBON_MONOXIDE_DETECTED, | ||
| DEVICE_CLASS_MOISTURE, SERV_LEAK_SENSOR, CHAR_LEAK_DETECTED, | ||
| DEVICE_CLASS_MOTION, SERV_MOTION_SENSOR, CHAR_MOTION_DETECTED, | ||
| DEVICE_CLASS_OCCUPANCY, SERV_OCCUPANCY_SENSOR, CHAR_OCCUPANCY_DETECTED, | ||
| DEVICE_CLASS_OPENING, SERV_CONTACT_SENSOR, CHAR_CONTACT_SENSOR_STATE, | ||
| DEVICE_CLASS_SMOKE, SERV_SMOKE_SENSOR, CHAR_SMOKE_DETECTED) | ||
| from .util import convert_to_float, temperature_to_homekit | ||
|
|
||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| BINARY_SENSOR_SERVICE_MAP = { | ||
| DEVICE_CLASS_CO2: | ||
| (SERV_CARBON_DIOXIDE_SENSOR, CHAR_CARBON_DIOXIDE_DETECTED), | ||
| DEVICE_CLASS_GAS: | ||
| (SERV_CARBON_MONOXIDE_SENSOR, CHAR_CARBON_MONOXIDE_DETECTED), | ||
| DEVICE_CLASS_MOISTURE: | ||
| (SERV_LEAK_SENSOR, CHAR_LEAK_DETECTED), | ||
| DEVICE_CLASS_MOTION: | ||
| (SERV_MOTION_SENSOR, CHAR_MOTION_DETECTED), | ||
| DEVICE_CLASS_OCCUPANCY: | ||
| (SERV_OCCUPANCY_SENSOR, CHAR_OCCUPANCY_DETECTED), | ||
| DEVICE_CLASS_OPENING: | ||
| (SERV_CONTACT_SENSOR, CHAR_CONTACT_SENSOR_STATE), | ||
| DEVICE_CLASS_SMOKE: | ||
| (SERV_SMOKE_SENSOR, CHAR_SMOKE_DETECTED)} | ||
|
|
||
|
|
||
| @TYPES.register('TemperatureSensor') | ||
| class TemperatureSensor(HomeAccessory): | ||
| """Generate a TemperatureSensor accessory for a temperature sensor. | ||
|
|
@@ -75,3 +101,35 @@ def update_state(self, entity_id=None, old_state=None, new_state=None): | |
| self.char_humidity.set_value(humidity, should_callback=False) | ||
| _LOGGER.debug('%s: Percent set to %d%%', | ||
| self.entity_id, humidity) | ||
|
|
||
|
|
||
| @TYPES.register('BinarySensor') | ||
| class BinarySensor(HomeAccessory): | ||
| """Generate a BinarySensor accessory as binary sensor.""" | ||
|
|
||
| def __init__(self, hass, entity_id, name, **kwargs): | ||
| """Initialize a BinarySensor accessory object.""" | ||
| super().__init__(name, entity_id, CATEGORY_SENSOR, **kwargs) | ||
|
|
||
| self.hass = hass | ||
| self.entity_id = entity_id | ||
|
|
||
| device_class = hass.states.get(entity_id).attributes \ | ||
| .get(ATTR_DEVICE_CLASS) | ||
| service_char = BINARY_SENSOR_SERVICE_MAP[device_class] \ | ||
| if device_class in BINARY_SENSOR_SERVICE_MAP \ | ||
| else BINARY_SENSOR_SERVICE_MAP[DEVICE_CLASS_OCCUPANCY] | ||
|
|
||
| service = add_preload_service(self, service_char[0]) | ||
| self.char_detected = service.get_characteristic(service_char[1]) | ||
| self.char_detected.value = 0 | ||
|
|
||
| def update_state(self, entity_id=None, old_state=None, new_state=None): | ||
| """Update accessory after state change.""" | ||
| if new_state is None: | ||
| return | ||
|
|
||
| state = new_state.state | ||
| detected = (state == STATE_ON) or (state == STATE_HOME) | ||
| self.char_detected.set_value(detected, should_callback=False) | ||
|
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. We just updated HAP-python to 1.1.9. 'Should_callback=False' will no longer be necessary. You probably need to rebase your branch, take take advantage of the update. |
||
| _LOGGER.debug('%s: Set to %d', self.entity_id, detected) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
expected 2 blank lines, found 1