diff --git a/homeassistant/components/flo/binary_sensor.py b/homeassistant/components/flo/binary_sensor.py index bd623aa38bb..88675e571e7 100644 --- a/homeassistant/components/flo/binary_sensor.py +++ b/homeassistant/components/flo/binary_sensor.py @@ -37,6 +37,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class FloPendingAlertsBinarySensor(FloEntity, BinarySensorEntity): """Binary sensor that reports on if there are any pending system alerts.""" + _attr_device_class = DEVICE_CLASS_PROBLEM + def __init__(self, device): """Initialize the pending alerts binary sensor.""" super().__init__("pending_system_alerts", "Pending System Alerts", device) @@ -57,15 +59,12 @@ class FloPendingAlertsBinarySensor(FloEntity, BinarySensorEntity): "critical": self._device.pending_critical_alerts_count, } - @property - def device_class(self): - """Return the device class for the binary sensor.""" - return DEVICE_CLASS_PROBLEM - class FloWaterDetectedBinarySensor(FloEntity, BinarySensorEntity): """Binary sensor that reports if water is detected (for leak detectors).""" + _attr_device_class = DEVICE_CLASS_PROBLEM + def __init__(self, device): """Initialize the pending alerts binary sensor.""" super().__init__("water_detected", "Water Detected", device) @@ -74,8 +73,3 @@ class FloWaterDetectedBinarySensor(FloEntity, BinarySensorEntity): def is_on(self): """Return true if the Flo device is detecting water.""" return self._device.water_detected - - @property - def device_class(self): - """Return the device class for the binary sensor.""" - return DEVICE_CLASS_PROBLEM diff --git a/homeassistant/components/flo/entity.py b/homeassistant/components/flo/entity.py index 94683e2cb20..9f0e8029888 100644 --- a/homeassistant/components/flo/entity.py +++ b/homeassistant/components/flo/entity.py @@ -13,6 +13,9 @@ from .device import FloDeviceDataUpdateCoordinator class FloEntity(Entity): """A base class for Flo entities.""" + _attr_force_update = False + _attr_should_poll = False + def __init__( self, entity_type: str, @@ -21,21 +24,12 @@ class FloEntity(Entity): **kwargs, ) -> None: """Init Flo entity.""" - self._unique_id: str = f"{device.mac_address}_{entity_type}" - self._name: str = name + self._attr_name = name + self._attr_unique_id = f"{device.mac_address}_{entity_type}" + self._device: FloDeviceDataUpdateCoordinator = device self._state: Any = None - @property - def name(self) -> str: - """Return Entity's default name.""" - return self._name - - @property - def unique_id(self) -> str: - """Return a unique ID.""" - return self._unique_id - @property def device_info(self) -> DeviceInfo: """Return a device description for device registry.""" @@ -53,16 +47,6 @@ class FloEntity(Entity): """Return True if device is available.""" return self._device.available - @property - def force_update(self) -> bool: - """Force update this entity.""" - return False - - @property - def should_poll(self) -> bool: - """Poll state from device.""" - return False - async def async_update(self): """Update Flo entity.""" await self._device.async_request_refresh() diff --git a/homeassistant/components/flo/sensor.py b/homeassistant/components/flo/sensor.py index 1e362e75f8c..0504d451e14 100644 --- a/homeassistant/components/flo/sensor.py +++ b/homeassistant/components/flo/sensor.py @@ -60,16 +60,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class FloDailyUsageSensor(FloEntity, SensorEntity): """Monitors the daily water usage.""" + _attr_icon = WATER_ICON + _attr_unit_of_measurement = VOLUME_GALLONS + def __init__(self, device): """Initialize the daily water usage sensor.""" super().__init__("daily_consumption", NAME_DAILY_USAGE, device) self._state: float = None - @property - def icon(self) -> str: - """Return the daily usage icon.""" - return WATER_ICON - @property def state(self) -> float | None: """Return the current daily usage.""" @@ -77,11 +75,6 @@ class FloDailyUsageSensor(FloEntity, SensorEntity): return None return round(self._device.consumption_today, 1) - @property - def unit_of_measurement(self) -> str: - """Return gallons as the unit measurement for water.""" - return VOLUME_GALLONS - class FloSystemModeSensor(FloEntity, SensorEntity): """Monitors the current Flo system mode.""" @@ -102,16 +95,14 @@ class FloSystemModeSensor(FloEntity, SensorEntity): class FloCurrentFlowRateSensor(FloEntity, SensorEntity): """Monitors the current water flow rate.""" + _attr_icon = GAUGE_ICON + _attr_unit_of_measurement = "gpm" + def __init__(self, device): """Initialize the flow rate sensor.""" super().__init__("current_flow_rate", NAME_FLOW_RATE, device) self._state: float = None - @property - def icon(self) -> str: - """Return the daily usage icon.""" - return GAUGE_ICON - @property def state(self) -> float | None: """Return the current flow rate.""" @@ -119,15 +110,13 @@ class FloCurrentFlowRateSensor(FloEntity, SensorEntity): return None return round(self._device.current_flow_rate, 1) - @property - def unit_of_measurement(self) -> str: - """Return the unit measurement.""" - return "gpm" - class FloTemperatureSensor(FloEntity, SensorEntity): """Monitors the temperature.""" + _attr_device_class = DEVICE_CLASS_TEMPERATURE + _attr_unit_of_measurement = TEMP_FAHRENHEIT + def __init__(self, name, device): """Initialize the temperature sensor.""" super().__init__("temperature", name, device) @@ -140,20 +129,13 @@ class FloTemperatureSensor(FloEntity, SensorEntity): return None return round(self._device.temperature, 1) - @property - def unit_of_measurement(self) -> str: - """Return fahrenheit as the unit measurement for temperature.""" - return TEMP_FAHRENHEIT - - @property - def device_class(self) -> str | None: - """Return the device class for this sensor.""" - return DEVICE_CLASS_TEMPERATURE - class FloHumiditySensor(FloEntity, SensorEntity): """Monitors the humidity.""" + _attr_device_class = DEVICE_CLASS_HUMIDITY + _attr_unit_of_measurement = PERCENTAGE + def __init__(self, device): """Initialize the humidity sensor.""" super().__init__("humidity", NAME_HUMIDITY, device) @@ -166,20 +148,13 @@ class FloHumiditySensor(FloEntity, SensorEntity): return None return round(self._device.humidity, 1) - @property - def unit_of_measurement(self) -> str: - """Return percent as the unit measurement for humidity.""" - return PERCENTAGE - - @property - def device_class(self) -> str | None: - """Return the device class for this sensor.""" - return DEVICE_CLASS_HUMIDITY - class FloPressureSensor(FloEntity, SensorEntity): """Monitors the water pressure.""" + _attr_device_class = DEVICE_CLASS_PRESSURE + _attr_unit_of_measurement = PRESSURE_PSI + def __init__(self, device): """Initialize the pressure sensor.""" super().__init__("water_pressure", NAME_WATER_PRESSURE, device) @@ -192,20 +167,13 @@ class FloPressureSensor(FloEntity, SensorEntity): return None return round(self._device.current_psi, 1) - @property - def unit_of_measurement(self) -> str: - """Return gallons as the unit measurement for water.""" - return PRESSURE_PSI - - @property - def device_class(self) -> str | None: - """Return the device class for this sensor.""" - return DEVICE_CLASS_PRESSURE - class FloBatterySensor(FloEntity, SensorEntity): """Monitors the battery level for battery-powered leak detectors.""" + _attr_device_class = DEVICE_CLASS_BATTERY + _attr_unit_of_measurement = PERCENTAGE + def __init__(self, device): """Initialize the battery sensor.""" super().__init__("battery", NAME_BATTERY, device) @@ -215,13 +183,3 @@ class FloBatterySensor(FloEntity, SensorEntity): def state(self) -> float | None: """Return the current battery level.""" return self._device.battery_level - - @property - def unit_of_measurement(self) -> str: - """Return percentage as the unit measurement for battery.""" - return PERCENTAGE - - @property - def device_class(self) -> str | None: - """Return the device class for this sensor.""" - return DEVICE_CLASS_BATTERY