Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
75 changes: 69 additions & 6 deletions homeassistant/components/climate/ephember.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
import voluptuous as vol

from homeassistant.components.climate import (
ClimateDevice, PLATFORM_SCHEMA, STATE_HEAT, STATE_IDLE, SUPPORT_AUX_HEAT,
ClimateDevice, PLATFORM_SCHEMA, STATE_HEAT, STATE_OFF,
STATE_AUTO, SUPPORT_AUX_HEAT, SUPPORT_OPERATION_MODE,
SUPPORT_TARGET_TEMPERATURE)
from homeassistant.const import (
TEMP_CELSIUS, CONF_USERNAME, CONF_PASSWORD, ATTR_TEMPERATURE)
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['pyephember==0.1.1']
REQUIREMENTS = ['pyephember==0.2.0']

_LOGGER = logging.getLogger(__name__)

Expand All @@ -27,6 +28,8 @@
vol.Required(CONF_PASSWORD): cv.string
})

STATE_ALL_DAY = "all_day"


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the ephember thermostat."""
Expand Down Expand Up @@ -61,9 +64,11 @@ def __init__(self, ember, zone):
def supported_features(self):
"""Return the list of supported features."""
if self._hot_water:
return SUPPORT_AUX_HEAT
return SUPPORT_AUX_HEAT | SUPPORT_OPERATION_MODE

return SUPPORT_TARGET_TEMPERATURE | SUPPORT_AUX_HEAT
return (SUPPORT_TARGET_TEMPERATURE |
SUPPORT_AUX_HEAT |
SUPPORT_OPERATION_MODE)

@property
def name(self):
Expand Down Expand Up @@ -93,12 +98,40 @@ def target_temperature_step(self):

return 1

@property
def device_state_attributes(self):
"""Show Device Attributes."""
attributes = {
'currently_active': self._zone['isCurrentlyActive']
}
return attributes

@property
def current_operation(self):
"""Return current operation ie. heat, cool, idle."""
mode = self._ember.get_zone_mode(self._zone_name)
return self.map_mode_eph_hass(mode)

@property
def operation_list(self):
"""Return the supported operations."""
return [STATE_AUTO, STATE_ALL_DAY, STATE_HEAT, STATE_OFF]

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.

Move this to a module level constant and return that here.

@MartinHjelmare MartinHjelmare Aug 12, 2018

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.

No operation modes that are not defined in the climate base component are allowed. Please remove STATE_ALL_DAY. New modes must be proposed and accepted via an issue in our architecture repo.

We're currently reviewing the climate component in our architecture repo.


def set_operation_mode(self, operation_mode):
"""Set the operation mode."""
mode = self.map_mode_hass_eph(operation_mode)
if mode is not None:
self._ember.set_mode_by_name(self._zone_name, mode)
else:
_LOGGER.error("Invalid operation mode provided %s", operation_mode)

@property
def is_on(self):
"""Return current state."""
if self._zone['isCurrentlyActive']:
return STATE_HEAT
return STATE_IDLE
return True

return None

@property
def is_aux_heat_on(self):
Expand Down Expand Up @@ -152,3 +185,33 @@ def max_temp(self):
def update(self):
"""Get the latest data."""
self._zone = self._ember.get_zone(self._zone_name)

@staticmethod
def map_mode_hass_eph(operation_mode):
"""Map from home assistant mode to eph mode."""
from pyephember.pyephember import ZoneMode
if operation_mode == STATE_AUTO:

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.

You can instead make a dictionary that holds the map, put at the module level, and use getattr on ZoneModehere to get the correct attribute.

return ZoneMode.AUTO
if operation_mode == STATE_ALL_DAY:
return ZoneMode.ALL_DAY
if operation_mode == STATE_HEAT:
return ZoneMode.ON
if operation_mode == STATE_OFF:
return ZoneMode.OFF

return None

@staticmethod
def map_mode_eph_hass(operation_mode):
"""Map from eph mode to home assistant mode."""
from pyephember.pyephember import ZoneMode
if operation_mode == ZoneMode.AUTO:

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.

return STATE_AUTO
if operation_mode == ZoneMode.ALL_DAY:
return STATE_ALL_DAY
if operation_mode == ZoneMode.ON:
return STATE_HEAT
if operation_mode == ZoneMode.OFF:
return STATE_OFF

return None
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ pyemby==1.5
pyenvisalink==2.2

# homeassistant.components.climate.ephember
pyephember==0.1.1
pyephember==0.2.0

# homeassistant.components.sensor.fido
pyfido==2.1.1
Expand Down