mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +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 vallox_websocket_api import PROFILE as VALLOX_PROFILE, Vallox
|
||||
from vallox_websocket_api.constants import vlxDevConstants
|
||||
from vallox_websocket_api.exceptions import ValloxApiException
|
||||
import voluptuous as vol
|
||||
|
||||
@ -98,20 +97,11 @@ class ValloxState:
|
||||
|
||||
def get_metric(self, metric_key: str) -> StateType:
|
||||
"""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:
|
||||
return None
|
||||
|
||||
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 value
|
||||
@ -126,8 +116,8 @@ class ValloxDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the client and boot the platforms."""
|
||||
conf = config[DOMAIN]
|
||||
host = conf.get(CONF_HOST)
|
||||
name = conf.get(CONF_NAME)
|
||||
host = conf[CONF_HOST]
|
||||
name = conf[CONF_NAME]
|
||||
|
||||
client = Vallox(host)
|
||||
|
||||
|
@ -35,7 +35,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ExtraStateAttributeDetails(NamedTuple):
|
||||
"""Extra state attribute properties."""
|
||||
"""Extra state attribute details."""
|
||||
|
||||
description: str
|
||||
metric_key: str
|
||||
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
@ -33,8 +32,6 @@ from .const import (
|
||||
VALLOX_PROFILE_TO_STR_REPORTABLE,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ValloxSensor(CoordinatorEntity, SensorEntity):
|
||||
"""Representation of a Vallox sensor."""
|
||||
@ -59,7 +56,6 @@ class ValloxSensor(CoordinatorEntity, SensorEntity):
|
||||
def native_value(self) -> StateType:
|
||||
"""Return the value reported by the sensor."""
|
||||
if (metric_key := self.entity_description.metric_key) is None:
|
||||
_LOGGER.debug("Error updating sensor. Empty metric key")
|
||||
return None
|
||||
|
||||
return self.coordinator.data.get_metric(metric_key)
|
||||
@ -100,7 +96,6 @@ class ValloxFilterRemainingSensor(ValloxSensor):
|
||||
super_native_value = super().native_value
|
||||
|
||||
if not isinstance(super_native_value, (int, float)):
|
||||
_LOGGER.debug("Value has unexpected type: %s", type(super_native_value))
|
||||
return None
|
||||
|
||||
# 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."""
|
||||
super_native_value = super().native_value
|
||||
|
||||
if not isinstance(super_native_value, (int, float)):
|
||||
_LOGGER.debug("Value has unexpected type: %s", type(super_native_value))
|
||||
if not isinstance(super_native_value, int):
|
||||
return None
|
||||
|
||||
return VALLOX_CELL_STATE_TO_STR.get(int(super_native_value))
|
||||
return VALLOX_CELL_STATE_TO_STR.get(super_native_value)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
Loading…
x
Reference in New Issue
Block a user