Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New climate device #17313

Merged
merged 5 commits into from Oct 14, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -437,6 +437,7 @@ omit =
homeassistant/components/climate/homematic.py
homeassistant/components/climate/honeywell.py
homeassistant/components/climate/knx.py
homeassistant/components/climate/mill.py
homeassistant/components/climate/oem.py
homeassistant/components/climate/opentherm_gw.py
homeassistant/components/climate/proliphix.py
Expand Down
158 changes: 158 additions & 0 deletions homeassistant/components/climate/mill.py
@@ -0,0 +1,158 @@
"""
Support for mill wifi-enabled home heaters.

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

import logging

import voluptuous as vol
from homeassistant.components.climate import (
ClimateDevice, PLATFORM_SCHEMA, SUPPORT_TARGET_TEMPERATURE,
SUPPORT_FAN_MODE, SUPPORT_ON_OFF)
from homeassistant.const import (
ATTR_TEMPERATURE, CONF_EMAIL, CONF_PASSWORD,
STATE_ON, STATE_OFF, TEMP_CELSIUS)
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession

REQUIREMENTS = ['millheater==0.1.1']

_LOGGER = logging.getLogger(__name__)

MAX_TEMP = 35
MIN_TEMP = 5
SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE |
SUPPORT_FAN_MODE | SUPPORT_ON_OFF)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_EMAIL): cv.string,
Copy link
Member

Choose a reason for hiding this comment

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

We most often use CONF_USERNAME even for email username. But you decide what fits best.

vol.Required(CONF_PASSWORD): cv.string,
})


async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the Mill heater."""
from mill import Mill
mill_data_connection = Mill(config[CONF_EMAIL],
config[CONF_PASSWORD],
websession=async_get_clientsession(hass))
if not await mill_data_connection.connect():
_LOGGER.error("Failed to connect to Mill")
return

await mill_data_connection.update_heaters()

dev = []
for heater in mill_data_connection.heaters.values():
dev.append(MilHeater(heater, mill_data_connection))
async_add_entities(dev)


class MilHeater(ClimateDevice):
Copy link
Member

Choose a reason for hiding this comment

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

Maybe call it MillHeater?

"""Representation of a Mill Thermostat device."""

def __init__(self, heater, mill_data_connection):
"""Initialize the thermostat."""
self._heater = heater
self._conn = mill_data_connection

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

@property
def available(self):
"""Return True if entity is available."""
return self._heater.device_status == 0 # weird api choice

@property
def state(self):
Copy link
Member

Choose a reason for hiding this comment

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

Overwrite is_on to communicate on/off state.

Copy link
Member

Choose a reason for hiding this comment

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

So we can remove state.

"""Return the current state."""
return STATE_ON if self._heater.power_status == 1 else STATE_OFF

@property
def unique_id(self):
"""Return a unique ID."""
return self._heater.device_id

@property
def name(self):
"""Return the name of the entity."""
return self._heater.name

@property
def temperature_unit(self):
"""Return the unit of measurement which this thermostat uses."""
return TEMP_CELSIUS

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

@property
def target_temperature_step(self):
"""Return the supported step of target temperature."""
return 1

@property
def current_temperature(self):
"""Return the current temperature."""
return self._heater.current_temp

@property
def current_fan_mode(self):
"""Return the fan setting."""
return STATE_ON if self._heater.fan_status == 1 else STATE_OFF

@property
def fan_list(self):
"""List of available fan modes."""
return [STATE_ON, STATE_OFF]

@property
def is_on(self):
"""Return true if heater is on."""
return True if self._heater.power_status == 1 else False
Copy link
Member

Choose a reason for hiding this comment

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

return self._heater.power_status == 1


@property
def min_temp(self):
"""Return the minimum temperature."""
return MIN_TEMP

@property
def max_temp(self):
"""Return the maximum temperature."""
return MAX_TEMP

async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None:
return
await self._conn.set_heater_temp(self._heater.device_id,
int(temperature))

async def async_set_fan_mode(self, fan_mode):
"""Set new target fan mode."""
fan_status = 1 if fan_mode == STATE_ON else 0
await self._conn.heater_control(self._heater.device_id,
fan_status=fan_status)

async def async_turn_on(self):
"""Turn Mill unit on."""
await self._conn.heater_control(self._heater.device_id,
power_status=1)

async def async_turn_off(self):
"""Turn Mill unit off."""
await self._conn.heater_control(self._heater.device_id,
power_status=0)

async def async_update(self):
"""Retrieve latest state."""
self._heater = await self._conn.update_device(self._heater.device_id)
3 changes: 3 additions & 0 deletions requirements_all.txt
Expand Up @@ -597,6 +597,9 @@ mficlient==0.3.0
# homeassistant.components.sensor.miflora
miflora==0.4.0

# homeassistant.components.climate.mill
millheater==0.1.1

# homeassistant.components.sensor.mitemp_bt
mitemp_bt==0.0.1

Expand Down