Bump pyefergy to 22.1.1 (#65156)
* Bump pyefergy to 22.1.0 * uno mas * uno mas * uno mas
This commit is contained in:
parent
c25431750e
commit
4a042e7d73
5 changed files with 27 additions and 21 deletions
|
@ -3,8 +3,10 @@ from __future__ import annotations
|
|||
|
||||
import logging
|
||||
from re import sub
|
||||
from typing import cast
|
||||
|
||||
from pyefergy import Efergy, exceptions
|
||||
from pyefergy import Efergy
|
||||
from pyefergy.exceptions import ConnectError, DataError, ServiceError
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
|
@ -16,6 +18,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_platform
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from . import EfergyEntity
|
||||
from .const import CONF_CURRENT_VALUES, DATA_KEY_API, DOMAIN
|
||||
|
@ -123,8 +126,8 @@ async def async_setup_entry(
|
|||
)
|
||||
)
|
||||
else:
|
||||
description.entity_registry_enabled_default = len(api.info["sids"]) > 1
|
||||
for sid in api.info["sids"]:
|
||||
description.entity_registry_enabled_default = len(api.sids) > 1
|
||||
for sid in api.sids:
|
||||
sensors.append(
|
||||
EfergySensor(
|
||||
api,
|
||||
|
@ -146,14 +149,16 @@ class EfergySensor(EfergyEntity, SensorEntity):
|
|||
server_unique_id: str,
|
||||
period: str | None = None,
|
||||
currency: str | None = None,
|
||||
sid: str = "",
|
||||
sid: int | None = None,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(api, server_unique_id)
|
||||
self.entity_description = description
|
||||
if description.key == CONF_CURRENT_VALUES:
|
||||
self._attr_name = f"{description.name}_{sid}"
|
||||
self._attr_unique_id = f"{server_unique_id}/{description.key}_{sid}"
|
||||
self._attr_name = f"{description.name}_{'' if sid is None else sid}"
|
||||
self._attr_unique_id = (
|
||||
f"{server_unique_id}/{description.key}_{'' if sid is None else sid}"
|
||||
)
|
||||
if "cost" in description.key:
|
||||
self._attr_native_unit_of_measurement = currency
|
||||
self.sid = sid
|
||||
|
@ -162,10 +167,11 @@ class EfergySensor(EfergyEntity, SensorEntity):
|
|||
async def async_update(self) -> None:
|
||||
"""Get the Efergy monitor data from the web service."""
|
||||
try:
|
||||
self._attr_native_value = await self.api.async_get_reading(
|
||||
data = await self.api.async_get_reading(
|
||||
self.entity_description.key, period=self.period, sid=self.sid
|
||||
)
|
||||
except (exceptions.DataError, exceptions.ConnectError) as ex:
|
||||
self._attr_native_value = cast(StateType, data)
|
||||
except (ConnectError, DataError, ServiceError) as ex:
|
||||
if self._attr_available:
|
||||
self._attr_available = False
|
||||
_LOGGER.error("Error getting data: %s", ex)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue