From 98163504fbc0ea14e580460904b767a1f5bafacd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8yer=20Iversen?= Date: Mon, 29 Oct 2018 23:36:49 +0100 Subject: [PATCH] Mill service (#17971) * Mill service * style --- homeassistant/components/climate/mill.py | 40 ++++++++++++++++--- .../components/climate/services.yaml | 16 ++++++++ requirements_all.txt | 2 +- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/climate/mill.py b/homeassistant/components/climate/mill.py index 8f058a3f05e..57d14126a93 100644 --- a/homeassistant/components/climate/mill.py +++ b/homeassistant/components/climate/mill.py @@ -10,7 +10,7 @@ import logging import voluptuous as vol from homeassistant.components.climate import ( - ClimateDevice, PLATFORM_SCHEMA, + ClimateDevice, DOMAIN, PLATFORM_SCHEMA, SUPPORT_TARGET_TEMPERATURE, SUPPORT_FAN_MODE, SUPPORT_ON_OFF) from homeassistant.const import ( @@ -19,12 +19,18 @@ from homeassistant.const import ( from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession -REQUIREMENTS = ['millheater==0.2.1'] +REQUIREMENTS = ['millheater==0.2.2'] _LOGGER = logging.getLogger(__name__) +ATTR_AWAY_TEMP = 'away_temp' +ATTR_COMFORT_TEMP = 'comfort_temp' +ATTR_ROOM_NAME = 'room_name' +ATTR_SLEEP_TEMP = 'sleep_temp' MAX_TEMP = 35 MIN_TEMP = 5 +SERVICE_SET_ROOM_TEMP = 'mill_set_room_temperature' + SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_ON_OFF) @@ -33,6 +39,13 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_PASSWORD): cv.string, }) +SET_ROOM_TEMP_SCHEMA = vol.Schema({ + vol.Required(ATTR_ROOM_NAME): cv.string, + vol.Optional(ATTR_AWAY_TEMP): cv.positive_int, + vol.Optional(ATTR_COMFORT_TEMP): cv.positive_int, + vol.Optional(ATTR_SLEEP_TEMP): cv.positive_int, +}) + async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): @@ -52,6 +65,20 @@ async def async_setup_platform(hass, config, async_add_entities, dev.append(MillHeater(heater, mill_data_connection)) async_add_entities(dev) + async def set_room_temp(service): + """Set room temp.""" + room_name = service.data.get(ATTR_ROOM_NAME) + sleep_temp = service.data.get(ATTR_SLEEP_TEMP) + comfort_temp = service.data.get(ATTR_COMFORT_TEMP) + away_temp = service.data.get(ATTR_AWAY_TEMP) + await mill_data_connection.set_room_temperatures_by_name(room_name, + sleep_temp, + comfort_temp, + away_temp) + + hass.services.async_register(DOMAIN, SERVICE_SET_ROOM_TEMP, + set_room_temp, schema=SET_ROOM_TEMP_SCHEMA) + class MillHeater(ClimateDevice): """Representation of a Mill Thermostat device.""" @@ -88,9 +115,12 @@ class MillHeater(ClimateDevice): room = self._heater.room.name else: room = "Independent device" - return {"room": room, - "open_window": self._heater.open_window, - "heating": self._heater.is_heating} + return { + "room": room, + "open_window": self._heater.open_window, + "heating": self._heater.is_heating, + "controlled_by_tibber": self._heater.tibber_control, + } @property def temperature_unit(self): diff --git a/homeassistant/components/climate/services.yaml b/homeassistant/components/climate/services.yaml index e2a42770cb2..1460181ddc2 100644 --- a/homeassistant/components/climate/services.yaml +++ b/homeassistant/components/climate/services.yaml @@ -116,6 +116,22 @@ ecobee_resume_program: description: Resume all events and return to the scheduled program. This default to false which removes only the top event. example: true +mill_set_room_temperature: + description: Set Mill room temperatures. + fields: + room_name: + description: Name of room to change. + example: 'kitchen' + away_temp: + description: Away temp. + example: 12 + comfort_temp: + description: Comfort temp. + example: 22 + sleep_temp: + description: Sleep temp. + example: 17 + nuheat_resume_program: description: Resume the programmed schedule. fields: diff --git a/requirements_all.txt b/requirements_all.txt index 7e3f42749d1..0865c388f4d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -615,7 +615,7 @@ mficlient==0.3.0 miflora==0.4.0 # homeassistant.components.climate.mill -millheater==0.2.1 +millheater==0.2.2 # homeassistant.components.sensor.mitemp_bt mitemp_bt==0.0.1