Support controlling Flowerbud spray level via homekit_controller (#53493)

This commit is contained in:
Jc2k 2021-07-26 16:46:36 +01:00 committed by GitHub
parent d58a02a647
commit 9a000a1183
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 725 additions and 0 deletions

View file

@ -0,0 +1,70 @@
"""Make sure that Vocolinc Flowerbud is enumerated properly."""
from homeassistant.helpers import device_registry as dr, entity_registry as er
from tests.components.homekit_controller.common import (
Helper,
setup_accessories_from_file,
setup_test_accessories,
)
async def test_vocolinc_flowerbud_setup(hass):
"""Test that a Vocolinc Flowerbud can be correctly setup in HA."""
accessories = await setup_accessories_from_file(hass, "vocolinc_flowerbud.json")
config_entry, pairing = await setup_test_accessories(hass, accessories)
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
# Check that the switch entity is handled correctly
entry = entity_registry.async_get("number.vocolinc_flowerbud_0d324b")
assert entry.unique_id == "homekit-AM01121849000327-aid:1-sid:30-cid:30"
helper = Helper(
hass, "number.vocolinc_flowerbud_0d324b", pairing, accessories[0], config_entry
)
state = await helper.poll_and_get_state()
assert state.attributes["friendly_name"] == "VOCOlinc-Flowerbud-0d324b"
device = device_registry.async_get(entry.device_id)
assert device.manufacturer == "VOCOlinc"
assert device.name == "VOCOlinc-Flowerbud-0d324b"
assert device.model == "Flowerbud"
assert device.sw_version == "3.121.2"
assert device.via_device_id is None
# Assert the humidifier is detected
entry = entity_registry.async_get("humidifier.vocolinc_flowerbud_0d324b")
assert entry.unique_id == "homekit-AM01121849000327-30"
helper = Helper(
hass,
"humidifier.vocolinc_flowerbud_0d324b",
pairing,
accessories[0],
config_entry,
)
state = await helper.poll_and_get_state()
assert state.attributes["friendly_name"] == "VOCOlinc-Flowerbud-0d324b"
# The sensor and switch should be part of the same device
assert entry.device_id == device.id
# Assert the light is detected
entry = entity_registry.async_get("light.vocolinc_flowerbud_0d324b")
assert entry.unique_id == "homekit-AM01121849000327-9"
helper = Helper(
hass,
"light.vocolinc_flowerbud_0d324b",
pairing,
accessories[0],
config_entry,
)
state = await helper.poll_and_get_state()
assert state.attributes["friendly_name"] == "VOCOlinc-Flowerbud-0d324b"
# The sensor and switch should be part of the same device
assert entry.device_id == device.id

View file

@ -0,0 +1,87 @@
"""Basic checks for HomeKit sensor."""
from aiohomekit.model.characteristics import CharacteristicsTypes
from aiohomekit.model.services import ServicesTypes
from tests.components.homekit_controller.common import Helper, setup_test_component
def create_switch_with_spray_level(accessory):
"""Define battery level characteristics."""
service = accessory.add_service(ServicesTypes.OUTLET)
spray_level = service.add_char(
CharacteristicsTypes.Vendor.VOCOLINC_HUMIDIFIER_SPRAY_LEVEL
)
spray_level.value = 1
spray_level.minStep = 1
spray_level.minValue = 1
spray_level.maxValue = 5
spray_level.format = "float"
cur_state = service.add_char(CharacteristicsTypes.ON)
cur_state.value = True
return service
async def test_read_number(hass, utcnow):
"""Test a switch service that has a sensor characteristic is correctly handled."""
helper = await setup_test_component(hass, create_switch_with_spray_level)
outlet = helper.accessory.services.first(service_type=ServicesTypes.OUTLET)
# Helper will be for the primary entity, which is the outlet. Make a helper for the sensor.
energy_helper = Helper(
hass,
"number.testdevice",
helper.pairing,
helper.accessory,
helper.config_entry,
)
outlet = energy_helper.accessory.services.first(service_type=ServicesTypes.OUTLET)
spray_level = outlet[CharacteristicsTypes.Vendor.VOCOLINC_HUMIDIFIER_SPRAY_LEVEL]
state = await energy_helper.poll_and_get_state()
assert state.state == "1"
assert state.attributes["step"] == 1
assert state.attributes["min"] == 1
assert state.attributes["max"] == 5
spray_level.value = 5
state = await energy_helper.poll_and_get_state()
assert state.state == "5"
async def test_write_number(hass, utcnow):
"""Test a switch service that has a sensor characteristic is correctly handled."""
helper = await setup_test_component(hass, create_switch_with_spray_level)
outlet = helper.accessory.services.first(service_type=ServicesTypes.OUTLET)
# Helper will be for the primary entity, which is the outlet. Make a helper for the sensor.
energy_helper = Helper(
hass,
"number.testdevice",
helper.pairing,
helper.accessory,
helper.config_entry,
)
outlet = energy_helper.accessory.services.first(service_type=ServicesTypes.OUTLET)
spray_level = outlet[CharacteristicsTypes.Vendor.VOCOLINC_HUMIDIFIER_SPRAY_LEVEL]
await hass.services.async_call(
"number",
"set_value",
{"entity_id": "number.testdevice", "value": 5},
blocking=True,
)
assert spray_level.value == 5
await hass.services.async_call(
"number",
"set_value",
{"entity_id": "number.testdevice", "value": 3},
blocking=True,
)
assert spray_level.value == 3