Skip to content
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
27 changes: 19 additions & 8 deletions homeassistant/components/danfoss_air/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
"""
Support for Danfoss Air HRV.

For more details about this component, please refer to the documentation at
https://home-assistant.io/components/danfoss_air/
"""
"""Support for Danfoss Air HRV."""
from datetime import timedelta
import logging

Expand All @@ -14,11 +9,11 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.util import Throttle

REQUIREMENTS = ['pydanfossair==0.0.6']
REQUIREMENTS = ['pydanfossair==0.0.7']

_LOGGER = logging.getLogger(__name__)

DANFOSS_AIR_PLATFORMS = ['sensor', 'binary_sensor']
DANFOSS_AIR_PLATFORMS = ['sensor', 'binary_sensor', 'switch']
DOMAIN = 'danfoss_air'

MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
Expand Down Expand Up @@ -57,6 +52,10 @@ def get_value(self, item):
"""Get value for sensor."""
return self._data.get(item)

def update_state(self, command, state_command):
"""Send update command to Danfoss Air CCM."""
self._data[state_command] = self._client.command(command)

@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Use the data from Danfoss Air API."""
Expand All @@ -76,5 +75,17 @@ def update(self):
= round(self._client.command(ReadCommand.filterPercent), 2)
self._data[ReadCommand.bypass] \
= self._client.command(ReadCommand.bypass)
self._data[ReadCommand.fan_step] \
= self._client.command(ReadCommand.fan_step)
self._data[ReadCommand.supply_fan_speed] \
= self._client.command(ReadCommand.supply_fan_speed)
self._data[ReadCommand.exhaust_fan_speed] \
= self._client.command(ReadCommand.exhaust_fan_speed)
self._data[ReadCommand.away_mode] \
= self._client.command(ReadCommand.away_mode)
self._data[ReadCommand.boost] \
= self._client.command(ReadCommand.boost)
self._data[ReadCommand.battery_percent] \
= self._client.command(ReadCommand.battery_percent)

_LOGGER.debug("Done fetching data from Danfoss Air CCM module")
20 changes: 10 additions & 10 deletions homeassistant/components/danfoss_air/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
"""
Support for the for Danfoss Air HRV binary sensor platform.

For more details about this component, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.danfoss_air/
"""
"""Support for the for Danfoss Air HRV binary sensors."""
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.components.danfoss_air import DOMAIN \
as DANFOSS_AIR_DOMAIN
Expand All @@ -14,25 +9,30 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
from pydanfossair.commands import ReadCommand
data = hass.data[DANFOSS_AIR_DOMAIN]

sensors = [["Danfoss Air Bypass Active", ReadCommand.bypass]]
sensors = [
["Danfoss Air Bypass Active", ReadCommand.bypass, "opening"],
["Danfoss Air Away Mode Active", ReadCommand.away_mode, None],
]

dev = []

for sensor in sensors:
dev.append(DanfossAirBinarySensor(data, sensor[0], sensor[1]))
dev.append(DanfossAirBinarySensor(
data, sensor[0], sensor[1], sensor[2]))

add_entities(dev, True)


class DanfossAirBinarySensor(BinarySensorDevice):
"""Representation of a Danfoss Air binary sensor."""

def __init__(self, data, name, sensor_type):
def __init__(self, data, name, sensor_type, device_class):
"""Initialize the Danfoss Air binary sensor."""
self._data = data
self._name = name
self._state = None
self._type = sensor_type
self._device_class = device_class

@property
def name(self):
Expand All @@ -47,7 +47,7 @@ def is_on(self):
@property
def device_class(self):
"""Type of device class."""
return "opening"
return self._device_class

def update(self):
"""Fetch new state data for the sensor."""
Expand Down
46 changes: 32 additions & 14 deletions homeassistant/components/danfoss_air/sensor.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""
Support for the for Danfoss Air HRV sensor platform.
"""Support for the for Danfoss Air HRV sensors."""
import logging

For more details about this component, please refer to the documentation at
https://home-assistant.io/components/sensor.danfoss_air/
"""
from homeassistant.components.danfoss_air import DOMAIN \
as DANFOSS_AIR_DOMAIN
from homeassistant.const import TEMP_CELSIUS
from homeassistant.const import (
TEMP_CELSIUS, DEVICE_CLASS_BATTERY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY)
from homeassistant.helpers.entity import Entity

_LOGGER = logging.getLogger(__name__)


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the available Danfoss Air sensors etc."""
Expand All @@ -18,43 +19,58 @@ def setup_platform(hass, config, add_entities, discovery_info=None):

sensors = [
["Danfoss Air Exhaust Temperature", TEMP_CELSIUS,
ReadCommand.exhaustTemperature],
ReadCommand.exhaustTemperature, DEVICE_CLASS_TEMPERATURE],
["Danfoss Air Outdoor Temperature", TEMP_CELSIUS,
ReadCommand.outdoorTemperature],
ReadCommand.outdoorTemperature, DEVICE_CLASS_TEMPERATURE],
["Danfoss Air Supply Temperature", TEMP_CELSIUS,
ReadCommand.supplyTemperature],
ReadCommand.supplyTemperature, DEVICE_CLASS_TEMPERATURE],
["Danfoss Air Extract Temperature", TEMP_CELSIUS,
ReadCommand.extractTemperature],
ReadCommand.extractTemperature, DEVICE_CLASS_TEMPERATURE],
["Danfoss Air Remaining Filter", '%',
ReadCommand.filterPercent],
ReadCommand.filterPercent, None],
["Danfoss Air Humidity", '%',
ReadCommand.humidity]
ReadCommand.humidity, DEVICE_CLASS_HUMIDITY],
["Danfoss Air Fan Step", '%',
ReadCommand.fan_step, None],
["Dandoss Air Exhaust Fan Speed", 'RPM',
ReadCommand.exhaust_fan_speed, None],
["Dandoss Air Supply Fan Speed", 'RPM',
ReadCommand.supply_fan_speed, None],
["Dandoss Air Dial Battery", '%',
ReadCommand.battery_percent, DEVICE_CLASS_BATTERY]
]

dev = []

for sensor in sensors:
dev.append(DanfossAir(data, sensor[0], sensor[1], sensor[2]))
dev.append(DanfossAir(
data, sensor[0], sensor[1], sensor[2], sensor[3]))

add_entities(dev, True)


class DanfossAir(Entity):
"""Representation of a Sensor."""

def __init__(self, data, name, sensor_unit, sensor_type):
def __init__(self, data, name, sensor_unit, sensor_type, device_class):
"""Initialize the sensor."""
self._data = data
self._name = name
self._state = None
self._type = sensor_type
self._unit = sensor_unit
self._device_class = device_class

@property
def name(self):
"""Return the name of the sensor."""
return self._name

@property
def device_class(self):
"""Return the device class of the sensor."""
return self._device_class

@property
def state(self):
"""Return the state of the sensor."""
Expand All @@ -74,3 +90,5 @@ def update(self):
self._data.update()

self._state = self._data.get_value(self._type)
if self._state is None:
_LOGGER.debug("Could not get data for %s", self._type)
72 changes: 72 additions & 0 deletions homeassistant/components/danfoss_air/switch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Support for the for Danfoss Air HRV sswitches."""
import logging

from homeassistant.components.switch import (
SwitchDevice)
from homeassistant.components.danfoss_air import DOMAIN \
as DANFOSS_AIR_DOMAIN

_LOGGER = logging.getLogger(__name__)


def setup_platform(hass, config, add_entities, discovery_info=None):
Comment thread
JonasPed1 marked this conversation as resolved.
"""Set up the Danfoss Air HRV switch platform."""
from pydanfossair.commands import ReadCommand, UpdateCommand

data = hass.data[DANFOSS_AIR_DOMAIN]

switches = [
["Danfoss Air Boost",
ReadCommand.boost,
UpdateCommand.boost_activate,
UpdateCommand.boost_deactivate],
]

dev = []

for switch in switches:
dev.append(DanfossAir(
data, switch[0], switch[1], switch[2], switch[3]))

add_entities(dev)


class DanfossAir(SwitchDevice):
"""Representation of a Danfoss Air HRV Switch."""

def __init__(self, data, name, state_command, on_command, off_command):
"""Initialize the switch."""
self._data = data
self._name = name
self._state_command = state_command
self._on_command = on_command
self._off_command = off_command
self._state = None

@property
def name(self):
"""Return the name of the switch."""
return self._name

@property
def is_on(self):
"""Return true if switch is on."""
return self._state

def turn_on(self, **kwargs):
"""Turn the switch on."""
_LOGGER.debug("Turning on switch with command %s", self._on_command)
self._data.update_state(self._on_command, self._state_command)

def turn_off(self, **kwargs):
"""Turn the switch off."""
_LOGGER.debug("Turning of switch with command %s", self._off_command)
self._data.update_state(self._off_command, self._state_command)

def update(self):
"""Update the switch's state."""
self._data.update()

self._state = self._data.get_value(self._state_command)
if self._state is None:
_LOGGER.debug("Could not get data for %s", self._state_command)
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ pycsspeechtts==1.0.2
pydaikin==0.9

# homeassistant.components.danfoss_air
pydanfossair==0.0.6
pydanfossair==0.0.7

# homeassistant.components.deconz
pydeconz==47
Expand Down