Skip to content

Commit

Permalink
fix: empty nodes on legacy (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed May 25, 2024
1 parent b98dbb6 commit d06f20e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 3 additions & 0 deletions custom_components/nexa_bridge_x/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
# This will always be true for legacy devices
FORCE_NODE_ENUM = False

# Force always polling on legacy devices
FORCE_NODE_POLL = False

NODE_MEDIA_CAPABILITIES = [
"mediaVolume",
"mediaPlayPause",
Expand Down
18 changes: 9 additions & 9 deletions custom_components/nexa_bridge_x/nexa.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
RECONNECT_SLEEP,
WS_PORT,
HTTP_BASIC_AUTH,
FORCE_NODE_ENUM
FORCE_NODE_ENUM,
FORCE_NODE_POLL
)
import dateutil.parser
import asyncio
Expand Down Expand Up @@ -81,10 +82,6 @@ def values_from_events(node: NexaNodeData, legacy: bool) -> list[NexaNodeValue]:
data[prev_key],
data["time"]
))
else:
if legacy and "capabilities" in node:
for key in node["capabilities"]:
values.append(NexaNodeValue(key, None, None, "0"))

return values

Expand Down Expand Up @@ -332,11 +329,13 @@ async def fetch_info(self) -> NexaInfoData:
"""Get information about bridge"""
return await self.request("get", "info")

async def fetch_nodes(self, skip_enum: bool) -> list[NexaNodeData]:
async def fetch_nodes(self, skip: bool) -> list[NexaNodeData]:
"""Get all configured nodes"""
result = await self.request("get", "nodes")
if skip and self.legacy:
return []

if (FORCE_NODE_ENUM or self.legacy) and not skip_enum:
result = await self.request("get", "nodes")
if FORCE_NODE_ENUM or self.legacy:
new_result = []
for r in result:
try:
Expand Down Expand Up @@ -668,11 +667,12 @@ async def _async_update_data(self) -> None:
"""Update data by pulling in the background"""
try:
timeout = POLL_TIMEOUT if self.has_polled else DISCOVERY_TIMEOUT
skip = False if FORCE_NODE_POLL else self.has_polled

async with async_timeout.timeout(timeout):
results = await asyncio.gather(*[
self.api.fetch_info(),
self.api.fetch_nodes(self.has_polled),
self.api.fetch_nodes(skip),
self.api.fetch_energy(),
self.api.fetch_energy_nodes(),
])
Expand Down

0 comments on commit d06f20e

Please sign in to comment.