Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error 3000 on SHC1 #88

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion custom_components/livisi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
VARIABLE_DEVICE_TYPES: Final = ["VariableActuator"]
VRCC_DEVICE_TYPES: Final = ["VRCC"]
WDS_DEVICE_TYPES: Final = ["WDS", "BT-WDS"]
CONTROLLER_DEVICE_TYPES: Final = ["SHC", "SHC2"] # TODO: Is this the right type?

BATTERY_POWERED_DEVICES = [
"BRC8",
Expand Down
48 changes: 17 additions & 31 deletions custom_components/livisi/livisi_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from aiohttp.client import ClientSession, ClientError, TCPConnector
from dateutil.parser import parse as parse_timestamp

from custom_components.livisi.const import CONTROLLER_DEVICE_TYPES

from .livisi_device import LivisiDevice

from .livisi_json_util import parse_dataclass
Expand All @@ -27,11 +25,11 @@
from .livisi_websocket import LivisiWebsocket

from .livisi_const import (
CONTROLLER_DEVICE_TYPES,
V1_NAME,
V2_NAME,
LOGGER,
REQUEST_TIMEOUT,
SHC2_ID,
WEBSERVICE_PORT,
)

Expand Down Expand Up @@ -231,20 +229,6 @@ async def async_get_devices(
return_exceptions=True,
)

if self.controller.is_v2:
shc_state = await self.async_send_authorized_request(
"get", path=f"device/{SHC2_ID}/state"
)

if self.controller.is_v1:
controller_device = next((x for x in devices if x["type"] == "SHC"), None)
if controller_device:
shc_state = (
await self.async_send_authorized_request(
"get", path=f"device/{controller_device['id']}/state"
)
)["state"]

for result, path in zip(
(devices, capabilities, rooms),
("device", "capability", "location"),
Expand All @@ -253,6 +237,20 @@ async def async_get_devices(
LOGGER.warn(f"Error loading {path}")
raise result # Re-raise the exception immediately

controller_id = next(
(x.get("id") for x in devices if x.get("type") in CONTROLLER_DEVICE_TYPES),
None,
)
if controller_id is not None:
try:
shc_state = await self.async_send_authorized_request(
"get", path=f"device/{controller_id}/state"
)
if self.controller.is_v1:
shc_state = shc_state["state"]
except Exception:
LOGGER.warning("Error getting shc state", exc_info=True)

capability_map = {}
capability_config = {}

Expand Down Expand Up @@ -292,20 +290,8 @@ async def async_get_devices(
roomid = device["location"].removeprefix("/location/")
device["room"] = room_map.get(roomid)

# TODO: Can we remove this if the controller Device types match?
# For SHC2
if device_id == SHC2_ID:
if isinstance(shc_state, Exception):
device["state"] = {}
else:
device["state"] = shc_state

# For SHC1
if device["type"] in CONTROLLER_DEVICE_TYPES:
if isinstance(shc_state, Exception):
device["state"] = {}
else:
device["state"] = shc_state
device["state"] = shc_state

devicelist.append(parse_dataclass(device, LivisiDevice))

Expand Down Expand Up @@ -335,7 +321,7 @@ def parse_messages(self, messages):
d.removeprefix("/device/") for d in message.get("devices", [])
]
if len(device_ids) == 0:
source = message.get("source", SHC2_ID)
source = message.get("source", "")
device_ids = [source.replace("/device/", "")]
if msgtype == "DeviceLowBattery":
for device_id in device_ids:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/livisi/livisi_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
WEBSERVICE_PORT: Final = 8080
REQUEST_TIMEOUT: Final = 2000

SHC2_ID: Final = "00000000000000000000000000000000"
CONTROLLER_DEVICE_TYPES: Final = ["SHC", "SHCA"]

BATTERY_LOW: Final = "batteryLow"
UPDATE_AVAILABLE: Final = "DeviceUpdateAvailable"
Expand Down
2 changes: 2 additions & 0 deletions custom_components/livisi/livisi_controller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Code to represent a livisi device."""

from __future__ import annotations

from dataclasses import dataclass
Expand All @@ -12,5 +13,6 @@ class LivisiController:
serial_number: str
os_version: str

device_id: str
is_v2: bool
is_v1: bool
3 changes: 1 addition & 2 deletions custom_components/livisi/livisi_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

from dataclasses import dataclass

from custom_components.livisi.const import CONTROLLER_DEVICE_TYPES

from .livisi_const import CONTROLLER_DEVICE_TYPES


@dataclass
Expand Down
Loading