change update handling with variable for breack CCU2 (#3215)
parent
17a2cac7e1
commit
73036f4725
|
@ -109,6 +109,7 @@ CONF_REMOTE_IP = 'remote_ip'
|
|||
CONF_REMOTE_PORT = 'remote_port'
|
||||
CONF_RESOLVENAMES = 'resolvenames'
|
||||
CONF_DELAY = 'delay'
|
||||
CONF_VARIABLES = 'variables'
|
||||
|
||||
|
||||
DEVICE_SCHEMA = vol.Schema({
|
||||
|
@ -130,6 +131,7 @@ CONFIG_SCHEMA = vol.Schema({
|
|||
vol.Optional(CONF_USERNAME, default="Admin"): cv.string,
|
||||
vol.Optional(CONF_PASSWORD, default=""): cv.string,
|
||||
vol.Optional(CONF_DELAY, default=0.5): vol.Coerce(float),
|
||||
vol.Optional(CONF_VARIABLES, default=False): cv.boolean,
|
||||
}),
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
@ -182,6 +184,7 @@ def setup(hass, config):
|
|||
username = config[DOMAIN].get(CONF_USERNAME)
|
||||
password = config[DOMAIN].get(CONF_PASSWORD)
|
||||
HOMEMATIC_LINK_DELAY = config[DOMAIN].get(CONF_DELAY)
|
||||
use_variables = config[DOMAIN].get(CONF_VARIABLES)
|
||||
|
||||
if remote_ip is None or local_ip is None:
|
||||
_LOGGER.error("Missing remote CCU/Homegear or local address")
|
||||
|
@ -219,13 +222,16 @@ def setup(hass, config):
|
|||
|
||||
##
|
||||
# init HM variable
|
||||
variables = HOMEMATIC.getAllSystemVariables()
|
||||
variables = HOMEMATIC.getAllSystemVariables() if use_variables else {}
|
||||
hm_var_store = {}
|
||||
if variables is not None:
|
||||
for key, value in variables.items():
|
||||
entities.append(HMVariable(key, value))
|
||||
varia = HMVariable(key, value)
|
||||
hm_var_store.update({key: varia})
|
||||
entities.append(varia)
|
||||
|
||||
# add homematic entites
|
||||
entities.append(HMHub())
|
||||
entities.append(HMHub(hm_var_store, use_variables))
|
||||
component.add_entities(entities)
|
||||
|
||||
##
|
||||
|
@ -496,9 +502,13 @@ def _hm_service_virtualkey(call):
|
|||
class HMHub(Entity):
|
||||
"""The Homematic hub. I.e. CCU2/HomeGear."""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, variables_store, use_variables=False):
|
||||
"""Initialize Homematic hub."""
|
||||
self._state = STATE_UNKNOWN
|
||||
self._store = variables_store
|
||||
self._use_variables = use_variables
|
||||
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -525,14 +535,30 @@ class HMHub(Entity):
|
|||
"""Return true if device is available."""
|
||||
return True if HOMEMATIC is not None else False
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATE_HUB)
|
||||
def update(self):
|
||||
"""Update Hub data and all HM variables."""
|
||||
self._update_hub_state()
|
||||
self._update_variables_state()
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATE_HUB)
|
||||
def _update_hub_state(self):
|
||||
"""Retrieve latest state."""
|
||||
if HOMEMATIC is None:
|
||||
return
|
||||
state = HOMEMATIC.getServiceMessages()
|
||||
self._state = STATE_UNKNOWN if state is None else len(state)
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATE_VAR)
|
||||
def _update_variables_state(self):
|
||||
"""Retrive all variable data and update hmvariable states."""
|
||||
if HOMEMATIC is None or not self._use_variables:
|
||||
return
|
||||
variables = HOMEMATIC.getAllSystemVariables()
|
||||
if variables is not None:
|
||||
for key, value in variables.items():
|
||||
if key in self._store:
|
||||
self._store.get(key).hm_update(value)
|
||||
|
||||
|
||||
class HMVariable(Entity):
|
||||
"""The Homematic system variable."""
|
||||
|
@ -557,12 +583,16 @@ class HMVariable(Entity):
|
|||
"""Return the icon to use in the frontend, if any."""
|
||||
return "mdi:code-string"
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATE_VAR)
|
||||
def update(self):
|
||||
"""Retrieve latest state."""
|
||||
if HOMEMATIC is None:
|
||||
return
|
||||
self._state = HOMEMATIC.getSystemVariable(self._name)
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return false. Homematic Hub object update variable."""
|
||||
return False
|
||||
|
||||
def hm_update(self, value):
|
||||
"""Update variable over Hub object."""
|
||||
if value != self._state:
|
||||
self._state = value
|
||||
self.update_ha_state()
|
||||
|
||||
def hm_set(self, value):
|
||||
"""Set variable on homematic controller."""
|
||||
|
|
Loading…
Reference in New Issue