8000 Minor cleanups for Vallox by andre-richter · Pull Request #58384 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Minor cleanups for Vallox #58384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions homeassistant/components/vallox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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

Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/vallox/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


class ExtraStateAttributeDetails(NamedTuple):
"""Extra state attribute properties."""
"""Extra state attribute details."""

description: str
metric_key: str
Expand Down
10 changes: 2 additions & 8 deletions homeassistant/components/vallox/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from dataclasses import dataclass
from datetime import datetime, timedelta
import logging

from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
Expand Down Expand Up @@ -33,8 +32,6 @@
VALLOX_PROFILE_TO_STR_REPORTABLE,
)

_LOGGER = logging.getLogger(__name__)


class ValloxSensor(CoordinatorEntity, SensorEntity):
"""Representation of a Vallox sensor."""
Expand All @@ -59,7 +56,6 @@ def __init__(
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)
Expand Down Expand Up @@ -100,7 +96,6 @@ def native_value(self) -> StateType:
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
Expand All @@ -120,11 +115,10 @@ def native_value(self) -> StateType:
"""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
Expand Down
0