Add a select entity for homekit temperature display units (#100853)

This commit is contained in:
Jc2k 2023-09-25 14:53:01 +01:00 committed by GitHub
parent 23b239ba77
commit 7334bc7c9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 200 additions and 13 deletions

View file

@ -1,6 +1,7 @@
"""Basic checks for HomeKit select entities."""
from aiohomekit.model import Accessory
from aiohomekit.model.characteristics import CharacteristicsTypes
from aiohomekit.model.characteristics.const import TemperatureDisplayUnits
from aiohomekit.model.services import ServicesTypes
from homeassistant.core import HomeAssistant
@ -22,6 +23,16 @@ def create_service_with_ecobee_mode(accessory: Accessory):
return service
def create_service_with_temperature_units(accessory: Accessory):
"""Define a thermostat with ecobee mode characteristics."""
service = accessory.add_service(ServicesTypes.TEMPERATURE_SENSOR, add_required=True)
units = service.add_char(CharacteristicsTypes.TEMPERATURE_UNITS)
units.value = 0
return service
async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
"""Test we can migrate a select unique id."""
entity_registry = er.async_get(hass)
@ -125,3 +136,76 @@ async def test_write_current_mode(hass: HomeAssistant, utcnow) -> None:
ServicesTypes.THERMOSTAT,
{CharacteristicsTypes.VENDOR_ECOBEE_SET_HOLD_SCHEDULE: 2},
)
async def test_read_select(hass: HomeAssistant, utcnow) -> None:
"""Test the generic select can read the current value."""
helper = await setup_test_component(hass, create_service_with_temperature_units)
# Helper will be for the primary entity, which is the service. Make a helper for the sensor.
select_entity = Helper(
hass,
"select.testdevice_temperature_display_units",
helper.pairing,
helper.accessory,
helper.config_entry,
)
state = await select_entity.async_update(
ServicesTypes.TEMPERATURE_SENSOR,
{
CharacteristicsTypes.TEMPERATURE_UNITS: 0,
},
)
assert state.state == "celsius"
state = await select_entity.async_update(
ServicesTypes.TEMPERATURE_SENSOR,
{
CharacteristicsTypes.TEMPERATURE_UNITS: 1,
},
)
assert state.state == "fahrenheit"
async def test_write_select(hass: HomeAssistant, utcnow) -> None:
"""Test can set a value."""
helper = await setup_test_component(hass, create_service_with_temperature_units)
helper.accessory.services.first(service_type=ServicesTypes.THERMOSTAT)
# Helper will be for the primary entity, which is the service. Make a helper for the sensor.
current_mode = Helper(
hass,
"select.testdevice_temperature_display_units",
helper.pairing,
helper.accessory,
helper.config_entry,
)
await hass.services.async_call(
"select",
"select_option",
{
"entity_id": "select.testdevice_temperature_display_units",
"option": "fahrenheit",
},
blocking=True,
)
current_mode.async_assert_service_values(
ServicesTypes.TEMPERATURE_SENSOR,
{CharacteristicsTypes.TEMPERATURE_UNITS: TemperatureDisplayUnits.FAHRENHEIT},
)
await hass.services.async_call(
"select",
"select_option",
{
"entity_id": "select.testdevice_temperature_display_units",
"option": "celsius",
},
blocking=True,
)
current_mode.async_assert_service_values(
ServicesTypes.TEMPERATURE_SENSOR,
{CharacteristicsTypes.TEMPERATURE_UNITS: TemperatureDisplayUnits.CELSIUS},
)