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
81 changes: 81 additions & 0 deletions homeassistant/components/climate/velbus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""
Support for Velbus thermostat.

For more details about this platform, please refer to the documentation
https://home-assistant.io/components/climate.velbus/
"""
import logging

from homeassistant.components.climate import (
SUPPORT_OPERATION_MODE, SUPPORT_TARGET_TEMPERATURE, ClimateDevice)
from homeassistant.components.velbus import (
DOMAIN as VELBUS_DOMAIN, VelbusEntity)
from homeassistant.const import ATTR_TEMPERATURE

_LOGGER = logging.getLogger(__name__)

DEPENDENCIES = ['velbus']

OPERATION_LIST = ['comfort', 'day', 'night', 'safe']
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. Only states imported from the base climate component is allowed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how we can get all states to work in this case ...3
What do you suggest we use as a mapping?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the integration or what those modes do, so I don't have a suggestion at the moment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically those 4 are are all temperature presets

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The home assistant operation state explains how the thermostat tries to adjust temperature, eg heat, cool, auto, eco. It doesn't say what temperature the thermostat should set. We have target_temperature and set_temperature for that.

If I understand correctly 'comfort', 'day', 'night', 'safe' are levels of temperature the thermostat should try to keep? If so, we shouldn't use operation mode in home assistant to change those.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this means i will only have on operation mode in HA (heat)
and how do i handle the temperature levels?

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare Nov 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can set a specific temperature degree with set_temperature these modes are not required, right? I don't think we currently have any matching control options for these modes. But look at the base climate component features.


SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE)


async def async_setup_platform(
hass, config, async_add_entities, discovery_info=None):
"""Set up the Velbus thermostat platform."""
if discovery_info is None:
return

sensors = []
for sensor in discovery_info:
module = hass.data[VELBUS_DOMAIN].get_module(sensor[0])
channel = sensor[1]
sensors.append(VelbusClimate(module, channel))

async_add_entities(sensors)


class VelbusClimate(VelbusEntity, ClimateDevice):
"""Representation of a Velbus thermostat."""

@property
def supported_features(self):
"""Return the list off supported features."""
return SUPPORT_FLAGS

@property
def temperature_unit(self):
"""Return the unit this state is expressed in."""
return self._module.get_unit(self._channel)

@property
def current_temperature(self):
"""Return the current temperature."""
return self._module.get_state(self._channel)

@property
def current_operation(self):
"""Return current operation ie. heat, cool, idle."""
return self._module.get_climate_mode()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return one of the home assistant climate states.


@property
def operation_list(self):
"""Return the list of available operation modes."""
return OPERATION_LIST

@property
def target_temperature(self):
"""Return the temperature we try to reach."""
return self._module.get_climate_target()

def set_operation_mode(self, operation_mode):
"""Set new target operation mode."""
self._module.set_mode(operation_mode)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to convert from home assistant climate state to device mode and vice versa. Define two constant dicts at the module level that do this.

self.schedule_update_ha_state()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this. Let the state update callback update state.


def set_temperature(self, **kwargs):
"""Set new target temperatures."""
if kwargs.get(ATTR_TEMPERATURE) is not None:
self._module.set_temp(kwargs.get(ATTR_TEMPERATURE))
self.schedule_update_ha_state()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

5 changes: 4 additions & 1 deletion homeassistant/components/velbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from homeassistant.helpers.discovery import load_platform
from homeassistant.helpers.entity import Entity

REQUIREMENTS = ['python-velbus==2.0.20']
REQUIREMENTS = ['python-velbus==2.0.21']

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -47,6 +47,7 @@ def callback():
modules = controller.get_modules()
discovery_info = {
'switch': [],
'climate': [],
'binary_sensor': [],
'sensor': []
}
Expand All @@ -60,6 +61,8 @@ def callback():
))
load_platform(hass, 'switch', DOMAIN,
discovery_info['switch'], config)
load_platform(hass, 'climate', DOMAIN,
discovery_info['climate'], config)
load_platform(hass, 'binary_sensor', DOMAIN,
discovery_info['binary_sensor'], config)
load_platform(hass, 'sensor', DOMAIN,
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ python-telegram-bot==11.1.0
python-twitch-client==0.6.0

# homeassistant.components.velbus
python-velbus==2.0.20
python-velbus==2.0.21

# homeassistant.components.media_player.vlc
python-vlc==1.1.2
Expand Down