Support binary_sensor and device_tracker in HomeKit.#13735
Support binary_sensor and device_tracker in HomeKit.#13735cdce8p merged 7 commits intohome-assistant:devfrom Yonsm:homekit_binary_sensor
Conversation
There was a problem hiding this comment.
line too long (143 > 79 characters)
cdce8p
left a comment
There was a problem hiding this comment.
It's looking good so far. Unfortunately I can't test it until tomorrow evening (CET).
Since you dynamically assign the service and char, can you add tests to verify that the right ones where selected. You can get the service / char name with service.display_name or char.display_name. Those must be equal to the HomeKit char / service constants.
There was a problem hiding this comment.
continuation line under-indented for visual indent
There was a problem hiding this comment.
Please add this to the end. That way you improve the coverage.
self.hass.states.remove(entity_id)
self.hass.block_till_done()There was a problem hiding this comment.
Instead of L85 - L88, why not do something like that:
from homeassistant.components.homekit.type_sensors import BINARY_SENSOR_SERVICE_MAP
class TestHomekitSensors(unittest.TestCase):
#####
#####
def test_binary(self):
#####
#####
def test_binary_device_classes(self):
entity_id = 'binary_sensor.demo'
for device_class, (service, char) in BINARY_SENSOR_SERVICE_MAP.items():
self.hass.states.set(entity_id, STATE_OFF,
{ATTR_DEVICE_CLASS: device_class})
self.hass.block_till_done()
acc = BinarySensor(self.hass, entity_id, 'Binary Sensor', aid=2)
self.assertEqual(acc.get_service(service).display_name, service)
self.assertEqual(acc.char_detected.display_name, char)That way you check if every service and char can be added successfully.
Passed: tox -e py36 -- tests/components/homekit/test_type_sensors.py -x tox -e py36 -- tests/components/homekit/test_get_accessories.py -x
1. Passed: tox -e py36 -- tests/components/homekit/test_type_sensors.py -x 2. And remove ‘# Ensure state.attributes’ comment
PASSED: tox -e py36 -- tests/components/homekit/test_type_sensors.py PASSED: script/lint (in my submit)
|
Thanks 👍 |
|
Thank you for your effective advice and guidance. |
|
cong~ merged! |
|
@Yonsm great, thanks a lot! @cdce8p maybe its possible to add a default mapping to binary_sensors with device_class "opening" for all sensors which returns states like "open/tilted/closed"? something similar to the existing temperature sensors. with that change I don't need to create extra template binary_sensors anymore :) |
|
@nicx There is a plan to add |
|
@cdce8p great to hear, I can wait for this 👍 keep up this great work! 🥇 |
|
Or maybe it's best to default to |
|
Please don't discuss feature requests in closed PRs. |
|
@MartinHjelmare seemed like an omission, what SHOULD I do instead? |
|
If you want to suggest an enhancement please open a feature request in the Feature Requests section of our community forum. Merged PRs should not be used for enhancement discussion or bug reports. If you've found a bug it's ok to make a review with inline comments and link to an issue that reports the bug. Thanks! |
…3735) * Support binary_sensor and device_tracker for HomeKit * Add test for get_accessory and binary sensor * Test service.display_name and char_detected.display_name * Split test to improve speed
Description:
Map binary_sensor and device_tracker to HomeKit Binary Sensor, based on 'device_class' attributes:
If there is no any matched device_class, e.g. device_tracker, then default sensor type is OccupancySensor.
Checklist:
tox.Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5143