Skip to content

Commit

Permalink
Do not process an unknown state updates (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwh committed Aug 1, 2022
1 parent 4d5adc8 commit f9b8ef2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
12 changes: 5 additions & 7 deletions custom_components/elro_connects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging

from elro.api import K1
from elro.device import ATTR_DEVICE_STATE, STATE_OFFLINE, STATE_UNKNOWN
from elro.device import ATTR_DEVICE_STATE, STATE_UNKNOWN

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import SERVICE_RELOAD, Platform
Expand All @@ -31,9 +31,9 @@ async def _async_update_data() -> dict[int, dict]:
nonlocal current_device_set
# get state from coordinator cash in case the current state is unknown
coordinator_update: dict[int, dict] = copy.deepcopy(coordinator.data or {})
# set initial state to offline
# set initial state to unknown
for device_id, state_base in coordinator_update.items():
state_base[ATTR_DEVICE_STATE] = STATE_OFFLINE
state_base[ATTR_DEVICE_STATE] = STATE_UNKNOWN
try:
await hass.async_create_task(elro_connects_api.async_update())
device_update = copy.deepcopy(elro_connects_api.data)
Expand All @@ -45,10 +45,8 @@ async def _async_update_data() -> dict[int, dict]:
# new device, or known state
coordinator_update[device_id] = device_data
elif device_data[ATTR_DEVICE_STATE] == STATE_UNKNOWN:
# update device state only, other data is not valid
coordinator_update[device_id][ATTR_DEVICE_STATE] = device_data[
ATTR_DEVICE_STATE
]
# do not process unknown state updates
continue
else:
# update full state
coordinator_update[device_id] = device_data
Expand Down
6 changes: 4 additions & 2 deletions custom_components/elro_connects/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from elro.utils import update_state_data

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_NAME, CONF_HOST, CONF_PORT
from homeassistant.const import ATTR_NAME, CONF_API_KEY, CONF_HOST, CONF_PORT
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
Expand Down Expand Up @@ -80,7 +80,9 @@ async def async_update_settings(
self, hass: HomeAssistant, entry: ConfigEntry
) -> None:
"""Process updated settings."""
await self.async_configure(entry.data[CONF_HOST], entry.data[CONF_PORT])
await self.async_configure(
entry.data[CONF_HOST], entry.data[CONF_PORT], entry.data.get(CONF_API_KEY)
)

@property
def data(self) -> dict[int, dict]:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/elro_connects/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://github.com/jbouwh/ha-elro-connects",
"issue_tracker": "https://github.com/jbouwh/ha-elro-connects/issues",
"requirements": ["lib-elro-connects==0.5.1"],
"requirements": ["lib-elro-connects==0.5.2"],
"codeowners": ["@jbouwh"],
"iot_class": "local_polling",
"version": "0.2.0"
Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pre-commit
lib-elro-connects==0.5.1
lib-elro-connects==0.5.2
homeassistant
pytest-homeassistant-custom-component
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ fnvhash==0.1.0

lru-dict==1.1.7

lib-elro-connects==0.5.1
lib-elro-connects==0.5.2

pytest-homeassistant-custom-component
2 changes: 1 addition & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ async def test_configure_platforms_dynamically(
async_fire_time_changed(hass, time)
await hass.async_block_till_done()

assert hass.states.get("siren.beganegrond").state == "unknown"
assert hass.states.get("siren.beganegrond").state == "off"
assert hass.states.get("siren.eerste_etage") is not None
assert hass.states.get("siren.zolder") is not None

0 comments on commit f9b8ef2

Please sign in to comment.