mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Migrate Flo to new entity naming style (#74744)
This commit is contained in:
parent
f95c9d0f02
commit
5971ab6549
@ -48,7 +48,7 @@ class FloPendingAlertsBinarySensor(FloEntity, BinarySensorEntity):
|
||||
|
||||
def __init__(self, device):
|
||||
"""Initialize the pending alerts binary sensor."""
|
||||
super().__init__("pending_system_alerts", "Pending System Alerts", device)
|
||||
super().__init__("pending_system_alerts", "Pending system alerts", device)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
@ -74,7 +74,7 @@ class FloWaterDetectedBinarySensor(FloEntity, BinarySensorEntity):
|
||||
|
||||
def __init__(self, device):
|
||||
"""Initialize the pending alerts binary sensor."""
|
||||
super().__init__("water_detected", "Water Detected", device)
|
||||
super().__init__("water_detected", "Water detected", device)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
|
@ -14,6 +14,7 @@ class FloEntity(Entity):
|
||||
"""A base class for Flo entities."""
|
||||
|
||||
_attr_force_update = False
|
||||
_attr_has_entity_name = True
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(
|
||||
@ -38,7 +39,7 @@ class FloEntity(Entity):
|
||||
identifiers={(FLO_DOMAIN, self._device.id)},
|
||||
manufacturer=self._device.manufacturer,
|
||||
model=self._device.model,
|
||||
name=self._device.device_name,
|
||||
name=self._device.device_name.capitalize(),
|
||||
sw_version=self._device.firmware_version,
|
||||
)
|
||||
|
||||
|
@ -22,12 +22,12 @@ from .entity import FloEntity
|
||||
|
||||
WATER_ICON = "mdi:water"
|
||||
GAUGE_ICON = "mdi:gauge"
|
||||
NAME_DAILY_USAGE = "Today's Water Usage"
|
||||
NAME_CURRENT_SYSTEM_MODE = "Current System Mode"
|
||||
NAME_FLOW_RATE = "Water Flow Rate"
|
||||
NAME_WATER_TEMPERATURE = "Water Temperature"
|
||||
NAME_DAILY_USAGE = "Today's water usage"
|
||||
NAME_CURRENT_SYSTEM_MODE = "Current system mode"
|
||||
NAME_FLOW_RATE = "Water flow rate"
|
||||
NAME_WATER_TEMPERATURE = "Water temperature"
|
||||
NAME_AIR_TEMPERATURE = "Temperature"
|
||||
NAME_WATER_PRESSURE = "Water Pressure"
|
||||
NAME_WATER_PRESSURE = "Water pressure"
|
||||
NAME_HUMIDITY = "Humidity"
|
||||
NAME_BATTERY = "Battery"
|
||||
|
||||
|
@ -68,7 +68,7 @@ class FloSwitch(FloEntity, SwitchEntity):
|
||||
|
||||
def __init__(self, device: FloDeviceDataUpdateCoordinator) -> None:
|
||||
"""Initialize the Flo switch."""
|
||||
super().__init__("shutoff_valve", "Shutoff Valve", device)
|
||||
super().__init__("shutoff_valve", "Shutoff valve", device)
|
||||
self._state = self._device.last_known_valve_state == "open"
|
||||
|
||||
@property
|
||||
|
@ -22,12 +22,17 @@ async def test_binary_sensors(hass, config_entry, aioclient_mock_fixture):
|
||||
|
||||
assert len(hass.data[FLO_DOMAIN][config_entry.entry_id]["devices"]) == 2
|
||||
|
||||
valve_state = hass.states.get("binary_sensor.pending_system_alerts")
|
||||
valve_state = hass.states.get(
|
||||
"binary_sensor.smart_water_shutoff_pending_system_alerts"
|
||||
)
|
||||
assert valve_state.state == STATE_ON
|
||||
assert valve_state.attributes.get("info") == 0
|
||||
assert valve_state.attributes.get("warning") == 2
|
||||
assert valve_state.attributes.get("critical") == 0
|
||||
assert valve_state.attributes.get(ATTR_FRIENDLY_NAME) == "Pending System Alerts"
|
||||
assert (
|
||||
valve_state.attributes.get(ATTR_FRIENDLY_NAME)
|
||||
== "Smart water shutoff Pending system alerts"
|
||||
)
|
||||
|
||||
detector_state = hass.states.get("binary_sensor.water_detected")
|
||||
detector_state = hass.states.get("binary_sensor.kitchen_sink_water_detected")
|
||||
assert detector_state.state == STATE_OFF
|
||||
|
@ -18,48 +18,63 @@ async def test_sensors(hass, config_entry, aioclient_mock_fixture):
|
||||
assert len(hass.data[FLO_DOMAIN][config_entry.entry_id]["devices"]) == 2
|
||||
|
||||
# we should have 5 entities for the valve
|
||||
assert hass.states.get("sensor.current_system_mode").state == "home"
|
||||
|
||||
assert hass.states.get("sensor.today_s_water_usage").state == "3.7"
|
||||
print(hass.states)
|
||||
assert (
|
||||
hass.states.get("sensor.today_s_water_usage").attributes[ATTR_STATE_CLASS]
|
||||
hass.states.get("sensor.smart_water_shutoff_current_system_mode").state
|
||||
== "home"
|
||||
)
|
||||
|
||||
assert (
|
||||
hass.states.get("sensor.smart_water_shutoff_today_s_water_usage").state == "3.7"
|
||||
)
|
||||
assert (
|
||||
hass.states.get("sensor.smart_water_shutoff_today_s_water_usage").attributes[
|
||||
ATTR_STATE_CLASS
|
||||
]
|
||||
== SensorStateClass.TOTAL_INCREASING
|
||||
)
|
||||
|
||||
assert hass.states.get("sensor.water_flow_rate").state == "0"
|
||||
assert hass.states.get("sensor.smart_water_shutoff_water_flow_rate").state == "0"
|
||||
assert (
|
||||
hass.states.get("sensor.water_flow_rate").attributes[ATTR_STATE_CLASS]
|
||||
hass.states.get("sensor.smart_water_shutoff_water_flow_rate").attributes[
|
||||
ATTR_STATE_CLASS
|
||||
]
|
||||
== SensorStateClass.MEASUREMENT
|
||||
)
|
||||
|
||||
assert hass.states.get("sensor.water_pressure").state == "54.2"
|
||||
assert hass.states.get("sensor.smart_water_shutoff_water_pressure").state == "54.2"
|
||||
assert (
|
||||
hass.states.get("sensor.water_pressure").attributes[ATTR_STATE_CLASS]
|
||||
hass.states.get("sensor.smart_water_shutoff_water_pressure").attributes[
|
||||
ATTR_STATE_CLASS
|
||||
]
|
||||
== SensorStateClass.MEASUREMENT
|
||||
)
|
||||
|
||||
assert hass.states.get("sensor.water_temperature").state == "21"
|
||||
assert hass.states.get("sensor.smart_water_shutoff_water_temperature").state == "21"
|
||||
assert (
|
||||
hass.states.get("sensor.water_temperature").attributes[ATTR_STATE_CLASS]
|
||||
hass.states.get("sensor.smart_water_shutoff_water_temperature").attributes[
|
||||
ATTR_STATE_CLASS
|
||||
]
|
||||
== SensorStateClass.MEASUREMENT
|
||||
)
|
||||
|
||||
# and 3 entities for the detector
|
||||
assert hass.states.get("sensor.temperature").state == "16"
|
||||
print(hass.states)
|
||||
assert hass.states.get("sensor.kitchen_sink_temperature").state == "16"
|
||||
assert (
|
||||
hass.states.get("sensor.temperature").attributes[ATTR_STATE_CLASS]
|
||||
hass.states.get("sensor.kitchen_sink_temperature").attributes[ATTR_STATE_CLASS]
|
||||
== SensorStateClass.MEASUREMENT
|
||||
)
|
||||
|
||||
assert hass.states.get("sensor.humidity").state == "43"
|
||||
assert hass.states.get("sensor.kitchen_sink_humidity").state == "43"
|
||||
assert (
|
||||
hass.states.get("sensor.humidity").attributes[ATTR_STATE_CLASS]
|
||||
hass.states.get("sensor.kitchen_sink_humidity").attributes[ATTR_STATE_CLASS]
|
||||
== SensorStateClass.MEASUREMENT
|
||||
)
|
||||
|
||||
assert hass.states.get("sensor.battery").state == "100"
|
||||
assert hass.states.get("sensor.kitchen_sink_battery").state == "100"
|
||||
assert (
|
||||
hass.states.get("sensor.battery").attributes[ATTR_STATE_CLASS]
|
||||
hass.states.get("sensor.kitchen_sink_battery").attributes[ATTR_STATE_CLASS]
|
||||
== SensorStateClass.MEASUREMENT
|
||||
)
|
||||
|
||||
@ -82,7 +97,7 @@ async def test_manual_update_entity(
|
||||
await hass.services.async_call(
|
||||
"homeassistant",
|
||||
"update_entity",
|
||||
{ATTR_ENTITY_ID: ["sensor.current_system_mode"]},
|
||||
{ATTR_ENTITY_ID: ["sensor.smart_water_shutoff_current_system_mode"]},
|
||||
blocking=True,
|
||||
)
|
||||
assert aioclient_mock.call_count == call_count + 3
|
||||
|
@ -17,7 +17,7 @@ from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import TEST_PASSWORD, TEST_USER_ID
|
||||
|
||||
SWITCH_ENTITY_ID = "switch.shutoff_valve"
|
||||
SWITCH_ENTITY_ID = "switch.smart_water_shutoff_shutoff_valve"
|
||||
|
||||
|
||||
async def test_services(hass, config_entry, aioclient_mock_fixture, aioclient_mock):
|
||||
|
@ -17,7 +17,7 @@ async def test_valve_switches(hass, config_entry, aioclient_mock_fixture):
|
||||
|
||||
assert len(hass.data[FLO_DOMAIN][config_entry.entry_id]["devices"]) == 2
|
||||
|
||||
entity_id = "switch.shutoff_valve"
|
||||
entity_id = "switch.smart_water_shutoff_shutoff_valve"
|
||||
assert hass.states.get(entity_id).state == STATE_ON
|
||||
|
||||
await hass.services.async_call(
|
||||
|
Loading…
x
Reference in New Issue
Block a user