From 9ba0809852bb3848f1bab99525500dddd75b4fd6 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:53:35 +0100 Subject: [PATCH] Use WATER device class in suez water (#83650) Adjust device class for suez water --- homeassistant/components/suez_water/sensor.py | 69 ++++++++----------- 1 file changed, 27 insertions(+), 42 deletions(-) diff --git a/homeassistant/components/suez_water/sensor.py b/homeassistant/components/suez_water/sensor.py index 4c0fe16a197..c6ee2332684 100644 --- a/homeassistant/components/suez_water/sensor.py +++ b/homeassistant/components/suez_water/sensor.py @@ -13,7 +13,7 @@ from homeassistant.components.sensor import ( SensorDeviceClass, SensorEntity, ) -from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, VOLUME_LITERS +from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, UnitOfVolume from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -25,9 +25,6 @@ SCAN_INTERVAL = timedelta(hours=12) CONF_COUNTER_ID = "counter_id" -NAME = "Suez Water Client" -ICON = "mdi:water-pump" - PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_USERNAME): cv.string, @@ -64,67 +61,55 @@ def setup_platform( class SuezSensor(SensorEntity): """Representation of a Sensor.""" - _attr_name = NAME - _attr_icon = ICON - _attr_native_unit_of_measurement = VOLUME_LITERS - _attr_device_class = SensorDeviceClass.VOLUME + _attr_name = "Suez Water Client" + _attr_icon = "mdi:water-pump" + _attr_native_unit_of_measurement = UnitOfVolume.LITERS + _attr_device_class = SensorDeviceClass.WATER - def __init__(self, client): + def __init__(self, client: SuezClient) -> None: """Initialize the data object.""" - self._attributes = {} - self._state = None - self._available = None self.client = client - - @property - def native_value(self): - """Return the state of the sensor.""" - return self._state - - @property - def extra_state_attributes(self): - """Return the state attributes.""" - return self._attributes + self._attr_extra_state_attributes = {} def _fetch_data(self): """Fetch latest data from Suez.""" try: self.client.update() # _state holds the volume of consumed water during previous day - self._state = self.client.state - self._available = True + self._attr_native_value = self.client.state + self._attr_available = True self._attr_attribution = self.client.attributes["attribution"] - self._attributes["this_month_consumption"] = {} + self._attr_extra_state_attributes["this_month_consumption"] = {} for item in self.client.attributes["thisMonthConsumption"]: - self._attributes["this_month_consumption"][ + self._attr_extra_state_attributes["this_month_consumption"][ item ] = self.client.attributes["thisMonthConsumption"][item] - self._attributes["previous_month_consumption"] = {} + self._attr_extra_state_attributes["previous_month_consumption"] = {} for item in self.client.attributes["previousMonthConsumption"]: - self._attributes["previous_month_consumption"][ + self._attr_extra_state_attributes["previous_month_consumption"][ item ] = self.client.attributes["previousMonthConsumption"][item] - self._attributes["highest_monthly_consumption"] = self.client.attributes[ - "highestMonthlyConsumption" - ] - self._attributes["last_year_overall"] = self.client.attributes[ - "lastYearOverAll" - ] - self._attributes["this_year_overall"] = self.client.attributes[ - "thisYearOverAll" - ] - self._attributes["history"] = {} + self._attr_extra_state_attributes[ + "highest_monthly_consumption" + ] = self.client.attributes["highestMonthlyConsumption"] + self._attr_extra_state_attributes[ + "last_year_overall" + ] = self.client.attributes["lastYearOverAll"] + self._attr_extra_state_attributes[ + "this_year_overall" + ] = self.client.attributes["thisYearOverAll"] + self._attr_extra_state_attributes["history"] = {} for item in self.client.attributes["history"]: - self._attributes["history"][item] = self.client.attributes["history"][ + self._attr_extra_state_attributes["history"][ item - ] + ] = self.client.attributes["history"][item] except PySuezError: - self._available = False + self._attr_available = False _LOGGER.warning("Unable to fetch data") def update(self) -> None: """Return the latest collected data from Linky.""" self._fetch_data() - _LOGGER.debug("Suez data state is: %s", self._state) + _LOGGER.debug("Suez data state is: %s", self.native_value)