Mill, support opeation mode (#18059)

This commit is contained in:
Daniel Høyer Iversen 2018-10-31 21:39:13 +01:00 committed by Pascal Vizeli
parent 7363378ac4
commit 145677ed75

View File

@ -10,9 +10,9 @@ import logging
import voluptuous as vol
from homeassistant.components.climate import (
ClimateDevice, DOMAIN, PLATFORM_SCHEMA,
ClimateDevice, DOMAIN, PLATFORM_SCHEMA, STATE_HEAT,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_FAN_MODE,
SUPPORT_ON_OFF)
SUPPORT_ON_OFF, SUPPORT_OPERATION_MODE)
from homeassistant.const import (
ATTR_TEMPERATURE, CONF_PASSWORD, CONF_USERNAME,
STATE_ON, STATE_OFF, TEMP_CELSIUS)
@ -32,7 +32,8 @@ MIN_TEMP = 5
SERVICE_SET_ROOM_TEMP = 'mill_set_room_temperature'
SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE |
SUPPORT_FAN_MODE | SUPPORT_ON_OFF)
SUPPORT_FAN_MODE | SUPPORT_ON_OFF |
SUPPORT_OPERATION_MODE)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_USERNAME): cv.string,
@ -167,6 +168,16 @@ class MillHeater(ClimateDevice):
"""Return the maximum temperature."""
return MAX_TEMP
@property
def current_operation(self):
"""Return current operation."""
return STATE_HEAT if self.is_on else STATE_OFF
@property
def operation_list(self):
"""List of available operation modes."""
return [STATE_HEAT, STATE_OFF]
async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
@ -194,3 +205,14 @@ class MillHeater(ClimateDevice):
async def async_update(self):
"""Retrieve latest state."""
self._heater = await self._conn.update_device(self._heater.device_id)
async def async_set_operation_mode(self, operation_mode):
"""Set operation mode."""
if operation_mode == STATE_HEAT:
await self.async_turn_on()
elif operation_mode == STATE_OFF:
await self.async_turn_off()
else:
_LOGGER.error("Unrecognized operation mode: %s", operation_mode)
return
self.schedule_update_ha_state()