mirror of
https://github.com/home-assistant/core.git
synced 2025-04-28 03:07:50 +00:00
Minor cleanups for Vallox (#58384)
This commit is contained in:
parent
f30963e15b
commit
b3f6be0cec
@ -7,7 +7,6 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from vallox_websocket_api import PROFILE as VALLOX_PROFILE, Vallox
|
from vallox_websocket_api import PROFILE as VALLOX_PROFILE, Vallox
|
||||||
from vallox_websocket_api.constants import vlxDevConstants
|
|
||||||
from vallox_websocket_api.exceptions import ValloxApiException
|
from vallox_websocket_api.exceptions import ValloxApiException
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -98,20 +97,11 @@ class ValloxState:
|
|||||||
|
|
||||||
def get_metric(self, metric_key: str) -> StateType:
|
def get_metric(self, metric_key: str) -> StateType:
|
||||||
"""Return cached state value."""
|
"""Return cached state value."""
|
||||||
_LOGGER.debug("Fetching metric key: %s", metric_key)
|
|
||||||
|
|
||||||
if metric_key not in vlxDevConstants.__dict__:
|
|
||||||
_LOGGER.debug("Metric key invalid: %s", metric_key)
|
|
||||||
|
|
||||||
if (value := self.metric_cache.get(metric_key)) is None:
|
if (value := self.metric_cache.get(metric_key)) is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not isinstance(value, (str, int, float)):
|
if not isinstance(value, (str, int, float)):
|
||||||
_LOGGER.debug(
|
|
||||||
"Return value of metric %s has unexpected type %s",
|
|
||||||
metric_key,
|
|
||||||
type(value),
|
|
||||||
)
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return value
|
return value
|
||||||
@ -126,8 +116,8 @@ class ValloxDataUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the client and boot the platforms."""
|
"""Set up the client and boot the platforms."""
|
||||||
conf = config[DOMAIN]
|
conf = config[DOMAIN]
|
||||||
host = conf.get(CONF_HOST)
|
host = conf[CONF_HOST]
|
||||||
name = conf.get(CONF_NAME)
|
name = conf[CONF_NAME]
|
||||||
|
|
||||||
client = Vallox(host)
|
client = Vallox(host)
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class ExtraStateAttributeDetails(NamedTuple):
|
class ExtraStateAttributeDetails(NamedTuple):
|
||||||
"""Extra state attribute properties."""
|
"""Extra state attribute details."""
|
||||||
|
|
||||||
description: str
|
description: str
|
||||||
metric_key: str
|
metric_key: str
|
||||||
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
STATE_CLASS_MEASUREMENT,
|
STATE_CLASS_MEASUREMENT,
|
||||||
@ -33,8 +32,6 @@ from .const import (
|
|||||||
VALLOX_PROFILE_TO_STR_REPORTABLE,
|
VALLOX_PROFILE_TO_STR_REPORTABLE,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class ValloxSensor(CoordinatorEntity, SensorEntity):
|
class ValloxSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""Representation of a Vallox sensor."""
|
"""Representation of a Vallox sensor."""
|
||||||
@ -59,7 +56,6 @@ class ValloxSensor(CoordinatorEntity, SensorEntity):
|
|||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType:
|
||||||
"""Return the value reported by the sensor."""
|
"""Return the value reported by the sensor."""
|
||||||
if (metric_key := self.entity_description.metric_key) is None:
|
if (metric_key := self.entity_description.metric_key) is None:
|
||||||
_LOGGER.debug("Error updating sensor. Empty metric key")
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return self.coordinator.data.get_metric(metric_key)
|
return self.coordinator.data.get_metric(metric_key)
|
||||||
@ -100,7 +96,6 @@ class ValloxFilterRemainingSensor(ValloxSensor):
|
|||||||
super_native_value = super().native_value
|
super_native_value = super().native_value
|
||||||
|
|
||||||
if not isinstance(super_native_value, (int, float)):
|
if not isinstance(super_native_value, (int, float)):
|
||||||
_LOGGER.debug("Value has unexpected type: %s", type(super_native_value))
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Since only a delta of days is received from the device, fix the time so the timestamp does
|
# Since only a delta of days is received from the device, fix the time so the timestamp does
|
||||||
@ -120,11 +115,10 @@ class ValloxCellStateSensor(ValloxSensor):
|
|||||||
"""Return the value reported by the sensor."""
|
"""Return the value reported by the sensor."""
|
||||||
super_native_value = super().native_value
|
super_native_value = super().native_value
|
||||||
|
|
||||||
if not isinstance(super_native_value, (int, float)):
|
if not isinstance(super_native_value, int):
|
||||||
_LOGGER.debug("Value has unexpected type: %s", type(super_native_value))
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return VALLOX_CELL_STATE_TO_STR.get(int(super_native_value))
|
return VALLOX_CELL_STATE_TO_STR.get(super_native_value)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user