Skip to content
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

Add integration for Vallox Ventilation Units #24660

Merged
merged 5 commits into from Jun 25, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Address review comments #2

  • Loading branch information...
andre-richter committed Jun 24, 2019
commit 7b74fd26eeea8c327a52eb8f39bc6441753120c3
@@ -139,9 +139,9 @@ def fetch_metric(self, metric_key):
_LOGGER.debug("Fetching metric key: %s", metric_key)

if not self._valid:
raise IOError("Device state out of sync.")
raise OSError("Device state out of sync.")

if metric_key not in vlxDevConstants.__dict__.keys():
if metric_key not in vlxDevConstants.__dict__:
raise KeyError("Unknown metric key: {}".format(metric_key))

return self._metric_cache[metric_key]
@@ -151,7 +151,7 @@ def get_profile(self):
_LOGGER.debug("Returning profile")

if not self._valid:
raise IOError("Device state out of sync.")
raise OSError("Device state out of sync.")

return PROFILE_TO_STR_REPORTABLE[self._profile]

@@ -36,13 +36,8 @@

client = hass.data[DOMAIN]['client']

try:
await hass.async_add_executor_job(
client.set_settable_address, METRIC_KEY_MODE, int)

except AttributeError as attr_err:
_LOGGER.error("Error making mode override settable: %s", attr_err)
return
await hass.async_add_executor_job(
client.set_settable_address, METRIC_KEY_MODE, int)

device = ValloxFan(hass.data[DOMAIN]['name'],
client,
@@ -124,7 +119,7 @@ def _update_callback(self):

self._available = True

except (IOError, KeyError) as err:
except (OSError, KeyError) as err:
self._available = False
_LOGGER.error("Error updating fan: %s", err)

@@ -1,9 +1,11 @@
"""Support for Vallox ventilation unit sensors."""

from datetime import datetime, timedelta
import logging

from homeassistant.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS)
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TIMESTAMP,
TEMP_CELSIUS)
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity
@@ -29,7 +31,6 @@
device_class=None,
unit_of_measurement=None,
icon='mdi:gauge'

),
ValloxFanSpeedSensor(
name="{} Fan Speed".format(name),
@@ -79,12 +80,12 @@
unit_of_measurement='%',
icon=None
),
ValloxSensor(
ValloxFilterRemainingSensor(
name="{} Remaining Time For Filter".format(name),
state_proxy=state_proxy,
metric_key='A_CYC_REMAINING_TIME_FOR_FILTER',
device_class=None,
unit_of_measurement='days',
device_class=DEVICE_CLASS_TIMESTAMP,
unit_of_measurement=None,
icon='mdi:filter'
),
]
@@ -158,7 +159,7 @@ def _update_callback(self):
self._state = self._state_proxy.fetch_metric(self._metric_key)
self._available = True

except (IOError, KeyError) as err:
except (OSError, KeyError) as err:
self._available = False
_LOGGER.error("Error updating sensor: %s", err)

@@ -184,7 +185,7 @@ class ValloxFanSpeedSensor(ValloxSensor):
self._state = 0
self._available = True

except (IOError, KeyError) as err:
except (OSError, KeyError) as err:
self._available = False
_LOGGER.error("Error updating sensor: %s", err)

@@ -204,6 +205,29 @@ def __init__(self, name, state_proxy, device_class, unit_of_measurement,
self._state = self._state_proxy.get_profile()
self._available = True

except IOError as err:
except OSError as err:
self._available = False
_LOGGER.error("Error updating sensor: %s", err)


class ValloxFilterRemainingSensor(ValloxSensor):
"""Child class for filter remaining time reporting."""

async def async_update(self):
"""Fetch state from the ventilation unit."""
try:
days_remaining = int(
self._state_proxy.fetch_metric(self._metric_key))
days_remaining_delta = timedelta(days=days_remaining)

# Since only a delta of days is received from the device, fix the
# time so the timestamp does not change with every update.
now = datetime.utcnow().replace(
hour=13, minute=0, second=0, microsecond=0)
This conversation was marked as resolved by MartinHjelmare

This comment has been minimized.

Copy link
@MartinHjelmare

MartinHjelmare Jun 24, 2019

Member

Very good!


self._state = (now + days_remaining_delta).isoformat()
self._available = True

except (OSError, KeyError) as err:
self._available = False
_LOGGER.error("Error updating sensor: %s", err)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.