mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Bugfix Homematic hub object (#9544)
* Bugfix Homematic hub object * fix hass instance * fix state unknow if 0 states
This commit is contained in:
parent
a8784f9adf
commit
3704a18da5
@ -18,7 +18,7 @@ from homeassistant.const import (
|
|||||||
CONF_PLATFORM, CONF_HOSTS, CONF_NAME, ATTR_ENTITY_ID)
|
CONF_PLATFORM, CONF_HOSTS, CONF_NAME, ATTR_ENTITY_ID)
|
||||||
from homeassistant.helpers import discovery
|
from homeassistant.helpers import discovery
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.event import async_track_time_interval
|
from homeassistant.helpers.event import track_time_interval
|
||||||
from homeassistant.config import load_yaml_config_file
|
from homeassistant.config import load_yaml_config_file
|
||||||
|
|
||||||
REQUIREMENTS = ['pyhomematic==0.1.32']
|
REQUIREMENTS = ['pyhomematic==0.1.32']
|
||||||
@ -292,7 +292,7 @@ def setup(hass, config):
|
|||||||
entity_hubs = []
|
entity_hubs = []
|
||||||
for _, hub_data in hosts.items():
|
for _, hub_data in hosts.items():
|
||||||
entity_hubs.append(HMHub(
|
entity_hubs.append(HMHub(
|
||||||
homematic, hub_data[CONF_NAME], hub_data[CONF_VARIABLES]))
|
hass, homematic, hub_data[CONF_NAME], hub_data[CONF_VARIABLES]))
|
||||||
|
|
||||||
# Register HomeMatic services
|
# Register HomeMatic services
|
||||||
descriptions = load_yaml_config_file(
|
descriptions = load_yaml_config_file(
|
||||||
@ -571,8 +571,9 @@ def _device_from_servicecall(hass, service):
|
|||||||
class HMHub(Entity):
|
class HMHub(Entity):
|
||||||
"""The HomeMatic hub. (CCU2/HomeGear)."""
|
"""The HomeMatic hub. (CCU2/HomeGear)."""
|
||||||
|
|
||||||
def __init__(self, homematic, name, use_variables):
|
def __init__(self, hass, homematic, name, use_variables):
|
||||||
"""Initialize HomeMatic hub."""
|
"""Initialize HomeMatic hub."""
|
||||||
|
self.hass = hass
|
||||||
self.entity_id = "{}.{}".format(DOMAIN, name.lower())
|
self.entity_id = "{}.{}".format(DOMAIN, name.lower())
|
||||||
self._homematic = homematic
|
self._homematic = homematic
|
||||||
self._variables = {}
|
self._variables = {}
|
||||||
@ -580,18 +581,15 @@ class HMHub(Entity):
|
|||||||
self._state = STATE_UNKNOWN
|
self._state = STATE_UNKNOWN
|
||||||
self._use_variables = use_variables
|
self._use_variables = use_variables
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def async_added_to_hass(self):
|
|
||||||
"""Load data init callbacks."""
|
|
||||||
# Load data
|
# Load data
|
||||||
async_track_time_interval(
|
track_time_interval(
|
||||||
self.hass, self._update_hub, SCAN_INTERVAL_HUB)
|
self.hass, self._update_hub, SCAN_INTERVAL_HUB)
|
||||||
yield from self.hass.async_add_job(self._update_hub, None)
|
self.hass.add_job(self._update_hub, None)
|
||||||
|
|
||||||
if self._use_variables:
|
if self._use_variables:
|
||||||
async_track_time_interval(
|
track_time_interval(
|
||||||
self.hass, self._update_variables, SCAN_INTERVAL_VARIABLES)
|
self.hass, self._update_variables, SCAN_INTERVAL_VARIABLES)
|
||||||
yield from self.hass.async_add_job(self._update_variables, None)
|
self.hass.add_job(self._update_variables, None)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -621,10 +619,12 @@ class HMHub(Entity):
|
|||||||
|
|
||||||
def _update_hub(self, now):
|
def _update_hub(self, now):
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
state = self._homematic.getServiceMessages(self._name)
|
service_message = self._homematic.getServiceMessages(self._name)
|
||||||
self._state = STATE_UNKNOWN if state is None else len(state)
|
state = None if service_message is None else len(service_message)
|
||||||
|
|
||||||
if now:
|
# state have change?
|
||||||
|
if self._state != state:
|
||||||
|
self._state = state
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def _update_variables(self, now):
|
def _update_variables(self, now):
|
||||||
@ -641,7 +641,7 @@ class HMHub(Entity):
|
|||||||
state_change = True
|
state_change = True
|
||||||
self._variables.update({key: value})
|
self._variables.update({key: value})
|
||||||
|
|
||||||
if state_change and now:
|
if state_change:
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def hm_set_variable(self, name, value):
|
def hm_set_variable(self, name, value):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user