Skip to content

Commit

Permalink
Update flexit for multi-device modbus
Browse files Browse the repository at this point in the history
  • Loading branch information
benvm committed Dec 20, 2018
1 parent 813d077 commit 3149ec6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions homeassistant/components/climate/flexit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
from homeassistant.components.climate import (
ClimateDevice, PLATFORM_SCHEMA, SUPPORT_TARGET_TEMPERATURE,
SUPPORT_FAN_MODE)
from homeassistant.components import modbus
from homeassistant.components.modbus import CONF_HUB_NAME, DOMAIN
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['pyflexit==0.3']
DEPENDENCIES = ['modbus']

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HUB_NAME, default="default"): cv.string,
vol.Required(CONF_SLAVE): vol.All(int, vol.Range(min=0, max=32)),
vol.Optional(CONF_NAME, default=DEVICE_DEFAULT_NAME): cv.string
})
Expand All @@ -40,15 +41,18 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Flexit Platform."""
modbus_slave = config.get(CONF_SLAVE, None)
name = config.get(CONF_NAME, None)
add_entities([Flexit(modbus_slave, name)], True)
hub_name = config.get(CONF_HUB_NAME)
hub = hass.data[DOMAIN][hub_name]
add_entities([Flexit(hub, modbus_slave, name)], True)


class Flexit(ClimateDevice):
"""Representation of a Flexit AC unit."""

def __init__(self, modbus_slave, name):
def __init__(self, hub, modbus_slave, name):
"""Initialize the unit."""
from pyflexit import pyflexit
self._hub = hub
self._name = name
self._slave = modbus_slave
self._target_temperature = None
Expand All @@ -64,7 +68,7 @@ def __init__(self, modbus_slave, name):
self._heating = None
self._cooling = None
self._alarm = False
self.unit = pyflexit.pyflexit(modbus.HUB, modbus_slave)
self.unit = pyflexit.pyflexit(hub, modbus_slave)

@property
def supported_features(self):
Expand Down

0 comments on commit 3149ec6

Please sign in to comment.