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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions homeassistant/components/vallox/__init__.py
Expand Up @@ -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]
Expand All @@ -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]

Expand Down
11 changes: 3 additions & 8 deletions homeassistant/components/vallox/fan.py
Expand Up @@ -36,13 +36,8 @@ async def async_setup_platform(hass, config, async_add_entities,

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,
Expand Down Expand Up @@ -124,7 +119,7 @@ async def async_update(self):

self._available = True

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

Expand Down
40 changes: 32 additions & 8 deletions homeassistant/components/vallox/sensor.py
@@ -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
Expand All @@ -29,7 +31,6 @@ async def async_setup_platform(hass, config, async_add_entities,
device_class=None,
unit_of_measurement=None,
icon='mdi:gauge'

),
ValloxFanSpeedSensor(
name="{} Fan Speed".format(name),
Expand Down Expand Up @@ -79,12 +80,12 @@ async def async_setup_platform(hass, config, async_add_entities,
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'
),
]
Expand Down Expand Up @@ -158,7 +159,7 @@ async def async_update(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)

Expand All @@ -184,7 +185,7 @@ async def async_update(self):
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)

Expand All @@ -204,6 +205,29 @@ async def async_update(self):
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)
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved

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)