mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Use WATER device class in suez water (#83650)
Adjust device class for suez water
This commit is contained in:
parent
9a97784168
commit
9ba0809852
@ -13,7 +13,7 @@ from homeassistant.components.sensor import (
|
|||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
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
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -25,9 +25,6 @@ SCAN_INTERVAL = timedelta(hours=12)
|
|||||||
|
|
||||||
CONF_COUNTER_ID = "counter_id"
|
CONF_COUNTER_ID = "counter_id"
|
||||||
|
|
||||||
NAME = "Suez Water Client"
|
|
||||||
ICON = "mdi:water-pump"
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
vol.Required(CONF_USERNAME): cv.string,
|
||||||
@ -64,67 +61,55 @@ def setup_platform(
|
|||||||
class SuezSensor(SensorEntity):
|
class SuezSensor(SensorEntity):
|
||||||
"""Representation of a Sensor."""
|
"""Representation of a Sensor."""
|
||||||
|
|
||||||
_attr_name = NAME
|
_attr_name = "Suez Water Client"
|
||||||
_attr_icon = ICON
|
_attr_icon = "mdi:water-pump"
|
||||||
_attr_native_unit_of_measurement = VOLUME_LITERS
|
_attr_native_unit_of_measurement = UnitOfVolume.LITERS
|
||||||
_attr_device_class = SensorDeviceClass.VOLUME
|
_attr_device_class = SensorDeviceClass.WATER
|
||||||
|
|
||||||
def __init__(self, client):
|
def __init__(self, client: SuezClient) -> None:
|
||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
self._attributes = {}
|
|
||||||
self._state = None
|
|
||||||
self._available = None
|
|
||||||
self.client = client
|
self.client = client
|
||||||
|
self._attr_extra_state_attributes = {}
|
||||||
@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
|
|
||||||
|
|
||||||
def _fetch_data(self):
|
def _fetch_data(self):
|
||||||
"""Fetch latest data from Suez."""
|
"""Fetch latest data from Suez."""
|
||||||
try:
|
try:
|
||||||
self.client.update()
|
self.client.update()
|
||||||
# _state holds the volume of consumed water during previous day
|
# _state holds the volume of consumed water during previous day
|
||||||
self._state = self.client.state
|
self._attr_native_value = self.client.state
|
||||||
self._available = True
|
self._attr_available = True
|
||||||
self._attr_attribution = self.client.attributes["attribution"]
|
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"]:
|
for item in self.client.attributes["thisMonthConsumption"]:
|
||||||
self._attributes["this_month_consumption"][
|
self._attr_extra_state_attributes["this_month_consumption"][
|
||||||
item
|
item
|
||||||
] = self.client.attributes["thisMonthConsumption"][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"]:
|
for item in self.client.attributes["previousMonthConsumption"]:
|
||||||
self._attributes["previous_month_consumption"][
|
self._attr_extra_state_attributes["previous_month_consumption"][
|
||||||
item
|
item
|
||||||
] = self.client.attributes["previousMonthConsumption"][item]
|
] = self.client.attributes["previousMonthConsumption"][item]
|
||||||
self._attributes["highest_monthly_consumption"] = self.client.attributes[
|
self._attr_extra_state_attributes[
|
||||||
"highestMonthlyConsumption"
|
"highest_monthly_consumption"
|
||||||
]
|
] = self.client.attributes["highestMonthlyConsumption"]
|
||||||
self._attributes["last_year_overall"] = self.client.attributes[
|
self._attr_extra_state_attributes[
|
||||||
"lastYearOverAll"
|
"last_year_overall"
|
||||||
]
|
] = self.client.attributes["lastYearOverAll"]
|
||||||
self._attributes["this_year_overall"] = self.client.attributes[
|
self._attr_extra_state_attributes[
|
||||||
"thisYearOverAll"
|
"this_year_overall"
|
||||||
]
|
] = self.client.attributes["thisYearOverAll"]
|
||||||
self._attributes["history"] = {}
|
self._attr_extra_state_attributes["history"] = {}
|
||||||
for item in self.client.attributes["history"]:
|
for item in self.client.attributes["history"]:
|
||||||
self._attributes["history"][item] = self.client.attributes["history"][
|
self._attr_extra_state_attributes["history"][
|
||||||
item
|
item
|
||||||
]
|
] = self.client.attributes["history"][item]
|
||||||
|
|
||||||
except PySuezError:
|
except PySuezError:
|
||||||
self._available = False
|
self._attr_available = False
|
||||||
_LOGGER.warning("Unable to fetch data")
|
_LOGGER.warning("Unable to fetch data")
|
||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
"""Return the latest collected data from Linky."""
|
"""Return the latest collected data from Linky."""
|
||||||
self._fetch_data()
|
self._fetch_data()
|
||||||
_LOGGER.debug("Suez data state is: %s", self._state)
|
_LOGGER.debug("Suez data state is: %s", self.native_value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user