mirror of
https://github.com/home-assistant/core.git
synced 2026-02-14 23:28:42 +00:00
Add WATER_LEVEL sensor to homekit_controller (#161900)
This commit is contained in:
@@ -30,6 +30,9 @@
|
||||
"sensor": {
|
||||
"valve_position": {
|
||||
"default": "mdi:pipe-valve"
|
||||
},
|
||||
"water_level": {
|
||||
"default": "mdi:water"
|
||||
}
|
||||
},
|
||||
"switch": {
|
||||
|
||||
@@ -356,6 +356,13 @@ SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = {
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
),
|
||||
CharacteristicsTypes.WATER_LEVEL: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.WATER_LEVEL,
|
||||
name="Water level",
|
||||
translation_key="water_level",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
CharacteristicsTypes.VENDOR_EVE_THERMO_VALVE_POSITION: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.VENDOR_EVE_THERMO_VALVE_POSITION,
|
||||
name="Valve position",
|
||||
|
||||
@@ -143,6 +143,9 @@
|
||||
"leader": "Leader",
|
||||
"router": "Router"
|
||||
}
|
||||
},
|
||||
"water_level": {
|
||||
"name": "Water level"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -70,6 +70,19 @@ def create_battery_level_sensor(accessory: Accessory) -> Service:
|
||||
return service
|
||||
|
||||
|
||||
def create_humidifier_with_water_level_sensor(accessory: Accessory) -> Service:
|
||||
"""Define a humidifier with a water level sensor."""
|
||||
service = accessory.add_service(ServicesTypes.HUMIDIFIER_DEHUMIDIFIER)
|
||||
|
||||
water_level = service.add_char(CharacteristicsTypes.WATER_LEVEL)
|
||||
water_level.value = 100
|
||||
|
||||
# The humidifier service needs other characteristics to be valid
|
||||
service.add_char(CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT).value = 30
|
||||
|
||||
return service
|
||||
|
||||
|
||||
async def test_temperature_sensor_read_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
@@ -278,6 +291,43 @@ async def test_battery_low(
|
||||
assert state.attributes["icon"] == "mdi:battery-alert"
|
||||
|
||||
|
||||
async def test_water_level_sensor_read_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test reading the state of a HomeKit water level sensor accessory."""
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_humidifier_with_water_level_sensor
|
||||
)
|
||||
|
||||
# Helper is for the primary entity, which is a humidifier.
|
||||
# Make a helper for the sensor.
|
||||
water_level_helper = Helper(
|
||||
hass,
|
||||
"sensor.testdevice_water_level",
|
||||
helper.pairing,
|
||||
helper.accessory,
|
||||
helper.config_entry,
|
||||
)
|
||||
|
||||
state = await water_level_helper.async_update(
|
||||
ServicesTypes.HUMIDIFIER_DEHUMIDIFIER,
|
||||
{
|
||||
CharacteristicsTypes.WATER_LEVEL: 10,
|
||||
},
|
||||
)
|
||||
assert state.state == "10"
|
||||
|
||||
state = await water_level_helper.async_update(
|
||||
ServicesTypes.HUMIDIFIER_DEHUMIDIFIER,
|
||||
{
|
||||
CharacteristicsTypes.WATER_LEVEL: 20,
|
||||
},
|
||||
)
|
||||
assert state.state == "20"
|
||||
|
||||
assert state.attributes["state_class"] == SensorStateClass.MEASUREMENT
|
||||
|
||||
|
||||
def create_switch_with_sensor(accessory: Accessory) -> Service:
|
||||
"""Define battery level characteristics."""
|
||||
service = accessory.add_service(ServicesTypes.OUTLET)
|
||||
|
||||
Reference in New Issue
Block a user