Skip to content

Commit

Permalink
Merge pull request #7 from scottyphillips/experimental
Browse files Browse the repository at this point in the history
Rebase to updated component from experimental.
  • Loading branch information
scottyphillips authored Jul 8, 2020
2 parents ee061ae + 47dfa6f commit 5f3bb76
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 141 deletions.
252 changes: 118 additions & 134 deletions custom_components/mitsubishi/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Mitsubishi platform to control HVAC using MAC-568IF-E Interface over ECHONET-lite
Protocol.
EXPERIMENTAL ASYNC UPDATE
Use this custom component for HA 0.96 and above
There are probably a lot of methods in here now that are obsolete with the
revised Climate class in HA 0.96
Expand All @@ -23,11 +25,10 @@
import logging
_LOGGER = logging.getLogger(__name__)

from homeassistant.components.climate import ClimateDevice
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_HUMIDITY,
SUPPORT_FAN_MODE, ATTR_FAN_MODES,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_FAN_MODE, ATTR_FAN_MODES,
CURRENT_HVAC_OFF, CURRENT_HVAC_HEAT, CURRENT_HVAC_COOL,
CURRENT_HVAC_DRY, CURRENT_HVAC_IDLE, CURRENT_HVAC_FAN,
HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_COOL,
Expand All @@ -36,15 +37,11 @@
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, ATTR_TEMPERATURE, CONF_HOST, CONF_IP_ADDRESS, CONF_NAME

DOMAIN = "mitsubishi"
REQUIREMENTS = ['mitsubishi_echonet==0.2.1']
REQUIREMENTS = ['mitsubishi_echonet==0.3']
SUPPORT_FLAGS = 0


def setup_platform(hass, config, add_entities, discovery_info=None):

async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
import mitsubishi_echonet as mit
#import custom_components.mitsubishi_echonet as mit

"""Set up the Mitsubishi ECHONET climate devices."""
entities = []
if config.get(CONF_IP_ADDRESS) is None:
Expand All @@ -59,20 +56,18 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
entities.append(MitsubishiClimate(config.get(CONF_NAME),
mit.HomeAirConditioner(config.get(CONF_IP_ADDRESS)),
TEMP_CELSIUS, config.get(ATTR_FAN_MODES)))
add_entities(entities)
async_add_entities(entities)


class MitsubishiClimate(ClimateDevice):
class MitsubishiClimate(ClimateEntity):

"""Representation of a Mitsubishi ECHONET climate device."""

def __init__(self, name, echonet_hvac, unit_of_measurement, fan_modes=None):

"""Initialize the climate device."""
self._name = name
self._api = echonet_hvac #new line
_LOGGER.debug("ECHONET lite HVAC %s component added to HA", self._api.netif)
# _LOGGER.debug("Available get attributes are %s", self._api.fetchGetProperties())

self._unit_of_measurement = unit_of_measurement
self._support_flags = SUPPORT_FLAGS
Expand All @@ -83,7 +78,7 @@ def __init__(self, name, echonet_hvac, unit_of_measurement, fan_modes=None):
data = self._api.update()

# Current and Target temperature
self._target_temperature = data['set_temperature'] if 'set_temerature' in data else 20
self._target_temperature = data['set_temperature'] if 'set_temperature' in data else 20
self._current_temperature = data['room_temperature'] if 'room_temperature' in data else 20

# Current power setting
Expand All @@ -93,15 +88,14 @@ def __init__(self, name, echonet_hvac, unit_of_measurement, fan_modes=None):
self._fan_mode= data['fan_speed'] if 'fan_speed' in data else 'medium-high'
if data['status'] is 'On':
self._hvac_mode = data['mode'] if 'mode' in data else 'heat_cool'
# Fix for heat_cool issue for HomeKit support.
if self._hvac_mode == 'auto':
self._hvac_mode = 'heat_cool'
else:
self._hvac_mode = 'off'

self._current_humidity = data['current_humidity'] if 'current_humidity' in data else None
self._target_humidity = data['target_humidity'] if 'target_humidity' in data else None
self._current_swing_mode = current_swing_mode if 'current_swing_mode' in data else None
# self._current_humidity = data['current_humidity'] if 'current_humidity' in data else None
# self._target_humidity = data['target_humidity'] if 'target_humidity' in data else None
# self._current_swing_mode = current_swing_mode if 'current_swing_mode' in data else None

except KeyError:
_LOGGER.warning("HA requested an update from HVAC %s but no data was received. Using Defaults", self._api.netif)
Expand All @@ -122,23 +116,22 @@ def __init__(self, name, echonet_hvac, unit_of_measurement, fan_modes=None):
else:
self._fan_modes = ['low', 'medium-high']
self._hvac_modes = ['heat', 'cool', 'dry','fan_only', 'heat_cool', 'off']
self._swing_list = ['auto', '1', '2', '3', 'off']
# self._swing_list = ['auto', '1', '2', '3', 'off']

def update(self):
async def async_update(self):
"""Get the latest state from the HVAC."""
try:
data = self._api.update()
if data is not False:
self._target_temperature = data['set_temperature']
self._current_temperature = data['room_temperature']
self._fan_mode= data['fan_speed']
self._hvac_mode = data['mode'] if data['status'] is 'On' else 'off'

# Shim for Home assistants 'auto' vs 'heat_cool' climate component debacle
if self._hvac_mode == 'auto':
self._hvac_mode = 'heat_cool'

self._on = True if data['status'] is 'On' else False
self._api.update()
self._target_temperature = self._api.setTemperature
self._current_temperature = self._api.roomTemperature
self._fan_mode = self._api.fan_speed
self._hvac_mode = self._api.mode if self._api.status is 'On' else 'off'

# Shim for Home assistants 'auto' vs 'heat_cool' stupidity
if self._hvac_mode == 'auto':
self._hvac_mode = 'heat_cool'

self._on = True if self._api.status is 'On' else False
except KeyError:
_LOGGER.warning("HA requested an update from HVAC %s but no data was received", self._api.netif)

Expand Down Expand Up @@ -172,26 +165,6 @@ def target_temperature(self):
"""Return the temperature we try to reach."""
return self._target_temperature

@property
def target_temperature_high(self):
"""Return the highbound target temperature we try to reach."""
return self._target_temperature_high

@property
def target_temperature_low(self):
"""Return the lowbound target temperature we try to reach."""
return self._target_temperature_low

@property
def current_humidity(self):
"""Return the current humidity."""
return self._current_humidity

@property
def target_humidity(self):
"""Return the humidity we try to reach."""
return self._target_humidity

@property
def hvac_mode(self):
"""Return current operation ie. heat, cool, idle."""
Expand All @@ -209,7 +182,6 @@ def hvac_action(self):
if self._hvac_mode == HVAC_MODE_FAN_ONLY:
return CURRENT_HVAC_FAN
if self._hvac_mode == HVAC_MODE_HEAT_COOL:
""" TODO : distinguish auto activity"""
if self._target_temperature < self._current_temperature:
return CURRENT_HVAC_COOL
if self._target_temperature > self._current_temperature:
Expand All @@ -222,21 +194,6 @@ def hvac_modes(self):
"""Return the list of available operation modes."""
return self._hvac_modes

@property
def is_away_mode_on(self):
"""Return if away mode is on."""
return self._away

@property
def current_hold_mode(self):
"""Return hold mode setting."""
return self._hold

@property
def is_aux_heat_on(self):
"""Return true if aux heat is on."""
return self._aux

@property
def is_on(self):
"""Return true if the device is on."""
Expand All @@ -252,7 +209,7 @@ def fan_modes(self):
"""Return the list of available fan modes."""
return self._fan_modes

def set_temperature(self, **kwargs):
async def async_set_temperature(self, **kwargs):
"""Set new target temperatures."""
if kwargs.get(ATTR_TEMPERATURE) is not None:
self._api.setOperationalTemperature(kwargs.get(ATTR_TEMPERATURE))
Expand All @@ -261,86 +218,113 @@ def set_temperature(self, **kwargs):
kwargs.get(ATTR_TARGET_TEMP_LOW) is not None:
self._target_temperature_high = kwargs.get(ATTR_TARGET_TEMP_HIGH)
self._target_temperature_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
self.schedule_update_ha_state()

def set_humidity(self, humidity):
"""Set new target temperature."""
self._target_humidity = humidity
self.schedule_update_ha_state()

def set_swing_mode(self, swing_mode):
"""Set new target temperature."""
self._current_swing_mode = swing_mode
self.schedule_update_ha_state()

def set_fan_mode(self, fan_mode):
async def async_set_fan_mode(self, fan_mode):
"""Set new target temperature."""
self._api.setFanSpeed(fan_mode)
self._fan_mode= fan_mode
self.schedule_update_ha_state()
self._fan_mode = self._api.fan_speed

def set_hvac_mode(self, operation_mode):
async def async_set_hvac_mode(self, hvac_mode):
"""Set new operation mode."""
if operation_mode == 'off':
self.turn_off()
if hvac_mode == 'off':
await self.async_turn_off()
else:
if self._on == False:
self.turn_on()
await self.async_turn_on()

# Shim for Home Assistants 'heat_cool' vs 'auto' ideological debate...
# 'heat_cool' mode is required to support proper HomeKit integration.
# The ECHONET standard only defines 'auto' and I am sticking to that convention
# with the API calls to the library.
if operation_mode == 'heat_cool':
# Shim for Home Assistants 'heat_cool' vs 'auto' stupidity
if hvac_mode == 'heat_cool':
self._api.setMode('auto')
else:
self._api.setMode(operation_mode)
self._hvac_mode = operation_mode
self.schedule_update_ha_state()
self._api.setMode(hvac_mode)
self._hvac_mode = hvac_mode

@property
def current_swing_mode(self):
"""Return the swing setting."""
return self._current_swing_mode

@property
def swing_list(self):
"""List of available swing modes."""
return self._swing_list

def turn_away_mode_on(self):
"""Turn away mode on."""
self._away = True
self.schedule_update_ha_state()

def turn_away_mode_off(self):
"""Turn away mode off."""
self._away = False
self.schedule_update_ha_state()

def set_hold_mode(self, hold_mode):
"""Update hold_mode on."""
self._hold = hold_mode
self.schedule_update_ha_state()

def turn_aux_heat_on(self):
"""Turn auxiliary heater on."""
self._aux = True
self.schedule_update_ha_state()

def turn_aux_heat_off(self):
"""Turn auxiliary heater off."""
self._aux = False
self.schedule_update_ha_state()

def turn_on(self):
async def async_turn_on(self):
"""Turn on."""
self._api.on()
self._on = True
self.schedule_update_ha_state()

def turn_off(self):
async def async_turn_off(self):
"""Turn off."""
self._api.off()
self._on = False
self.schedule_update_ha_state()

# @property
# def target_temperature_high(self):
# """Return the highbound target temperature we try to reach."""
# return self._target_temperature_high

# @property
# def target_temperature_low(self):
# """Return the lowbound target temperature we try to reach."""
# return self._target_temperature_low

# @property
# def current_swing_mode(self):
# """Return the swing setting."""
# return self._current_swing_mode

# @property
# def swing_list(self):
# """List of available swing modes."""
# return self._swing_list

# def turn_away_mode_on(self):
# """Turn away mode on."""
# self._away = True
# self.schedule_update_ha_state()

# def turn_away_mode_off(self):
# """Turn away mode off."""
# self._away = False
# self.schedule_update_ha_state()

# def set_hold_mode(self, hold_mode):
# """Update hold_mode on."""
# self._hold = hold_mode
# self.schedule_update_ha_state()

# def turn_aux_heat_on(self):
# """Turn auxiliary heater on."""
# self._aux = True
# self.schedule_update_ha_state()

# def turn_aux_heat_off(self):
# """Turn auxiliary heater off."""
# self._aux = False
# self.schedule_update_ha_state()

# def set_humidity(self, humidity):
# """Set new target temperature."""
# self._target_humidity = humidity
# # self.schedule_update_ha_state()

# def set_swing_mode(self, swing_mode):
# """Set new target temperature."""
# self._current_swing_mode = swing_mode
# # self.schedule_update_ha_state()

# @property
# def is_aux_heat_on(self):
# """Return true if aux heat is on."""
# return self._aux

# @property
# def is_away_mode_on(self):
# """Return if away mode is on."""
# return self._away

# @property
# def current_hold_mode(self):
# """Return hold mode setting."""
# return self._hold

# @property
# def current_humidity(self):
# """Return the current humidity."""
# return self._current_humidity

# @property
# def target_humidity(self):
# """Return the humidity we try to reach."""
# return self._target_humidity
23 changes: 23 additions & 0 deletions custom_components/mitsubishi/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from homeassistant.const import CONF_ICON, CONF_NAME, CONF_TYPE

ATTR_TARGET_TEMPERATURE = "target_temperature"
ATTR_INSIDE_TEMPERATURE = "inside_temperature"
ATTR_OUTSIDE_TEMPERATURE = "outside_temperature"

ATTR_STATE_ON = "on"
ATTR_STATE_OFF = "off"

SENSOR_TYPE_TEMPERATURE = "temperature"

SENSOR_TYPES = {
ATTR_INSIDE_TEMPERATURE: {
CONF_NAME: "Inside Temperature",
CONF_ICON: "mdi:thermometer",
CONF_TYPE: SENSOR_TYPE_TEMPERATURE,
},
ATTR_OUTSIDE_TEMPERATURE: {
CONF_NAME: "Outside Temperature",
CONF_ICON: "mdi:thermometer",
CONF_TYPE: SENSOR_TYPE_TEMPERATURE,
},
}
Loading

0 comments on commit 5f3bb76

Please sign in to comment.