1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00
This commit is contained in:
Paulus Schoutsen
2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View File

@@ -3,31 +3,36 @@ import logging
from homeassistant.components.climate import ClimateDevice
from homeassistant.components.climate.const import (
HVAC_MODE_AUTO, HVAC_MODE_COOL, HVAC_MODE_DRY, HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT, HVAC_MODE_OFF, SUPPORT_FAN_MODE,
SUPPORT_TARGET_TEMPERATURE)
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
SUPPORT_FAN_MODE,
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.components.fan import SPEED_HIGH, SPEED_LOW, SPEED_MEDIUM
from homeassistant.const import (
ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS)
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS
from . import DATA_MELISSA
_LOGGER = logging.getLogger(__name__)
SUPPORT_FLAGS = (SUPPORT_FAN_MODE | SUPPORT_TARGET_TEMPERATURE)
SUPPORT_FLAGS = SUPPORT_FAN_MODE | SUPPORT_TARGET_TEMPERATURE
OP_MODES = [
HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_DRY, HVAC_MODE_FAN_ONLY,
HVAC_MODE_OFF
HVAC_MODE_HEAT,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_OFF,
]
FAN_MODES = [
HVAC_MODE_AUTO, SPEED_HIGH, SPEED_MEDIUM, SPEED_LOW
]
FAN_MODES = [HVAC_MODE_AUTO, SPEED_HIGH, SPEED_MEDIUM, SPEED_LOW]
async def async_setup_platform(
hass, config, async_add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Iterate through and add all Melissa devices."""
api = hass.data[DATA_MELISSA]
devices = (await api.async_fetch_devices()).values()
@@ -35,9 +40,8 @@ async def async_setup_platform(
all_devices = []
for device in devices:
if device['type'] == 'melissa':
all_devices.append(MelissaClimate(
api, device['serial_number'], device))
if device["type"] == "melissa":
all_devices.append(MelissaClimate(api, device["serial_number"], device))
async_add_entities(all_devices)
@@ -47,10 +51,10 @@ class MelissaClimate(ClimateDevice):
def __init__(self, api, serial_number, init_data):
"""Initialize the climate device."""
self._name = init_data['name']
self._name = init_data["name"]
self._api = api
self._serial_number = serial_number
self._data = init_data['controller_log']
self._data = init_data["controller_log"]
self._state = None
self._cur_settings = None
@@ -63,8 +67,7 @@ class MelissaClimate(ClimateDevice):
def fan_mode(self):
"""Return the current fan mode."""
if self._cur_settings is not None:
return self.melissa_fan_to_hass(
self._cur_settings[self._api.FAN])
return self.melissa_fan_to_hass(self._cur_settings[self._api.FAN])
@property
def current_temperature(self):
@@ -90,7 +93,9 @@ class MelissaClimate(ClimateDevice):
return None
is_on = self._cur_settings[self._api.STATE] in (
self._api.STATE_ON, self._api.STATE_IDLE)
self._api.STATE_ON,
self._api.STATE_IDLE,
)
if not is_on:
return HVAC_MODE_OFF
@@ -160,21 +165,20 @@ class MelissaClimate(ClimateDevice):
self._cur_settings.update(value)
except AttributeError:
old_value = None
if not await self._api.async_send(
self._serial_number, self._cur_settings):
if not await self._api.async_send(self._serial_number, self._cur_settings):
self._cur_settings = old_value
async def async_update(self):
"""Get latest data from Melissa."""
try:
self._data = (await self._api.async_status(cached=True))[
self._serial_number]
self._cur_settings = (await self._api.async_cur_settings(
self._serial_number
))['controller']['_relation']['command_log']
]
self._cur_settings = (
await self._api.async_cur_settings(self._serial_number)
)["controller"]["_relation"]["command_log"]
except KeyError:
_LOGGER.warning(
'Unable to update entity %s', self.entity_id)
_LOGGER.warning("Unable to update entity %s", self.entity_id)
def melissa_op_to_hass(self, mode):
"""Translate Melissa modes to hass states."""
@@ -186,8 +190,7 @@ class MelissaClimate(ClimateDevice):
return HVAC_MODE_DRY
if mode == self._api.MODE_FAN:
return HVAC_MODE_FAN_ONLY
_LOGGER.warning(
"Operation mode %s could not be mapped to hass", mode)
_LOGGER.warning("Operation mode %s could not be mapped to hass", mode)
return None
def melissa_fan_to_hass(self, fan):