Skip to content

Commit

Permalink
Update light.py
Browse files Browse the repository at this point in the history
  • Loading branch information
azerty9971 committed Jan 27, 2025
1 parent 642d016 commit caaa996
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions custom_components/xtend_tuya/light.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Support for the XT lights."""

from __future__ import annotations

import json

from dataclasses import dataclass

from homeassistant.const import Platform
Expand All @@ -18,7 +19,12 @@
MultiManager,
XTDevice,
)
from .const import TUYA_DISCOVERY_NEW, DPCode
from .const import (
TUYA_DISCOVERY_NEW,
DPCode,
DPType,
LOGGER,
)
from .ha_tuya_integration.tuya_integration_imports import (
TuyaLightEntity,
TuyaLightEntityDescription,
Expand Down Expand Up @@ -86,7 +92,18 @@ def __init__(
device_manager: MultiManager,
description: XTLightEntityDescription,
) -> None:
super(XTLightEntity, self).__init__(device, device_manager, description)
try:
super(XTLightEntity, self).__init__(device, device_manager, description)
except Exception as e:
if (
dpcode := self.find_dpcode(description.color_data, prefer_function=True)
) and self.get_dptype(dpcode) == DPType.JSON:
if dpcode in self.device.function:
values = self.device.function[dpcode].values
else:
values = self.device.status_range[dpcode].values
if function_data := json.loads(values):
LOGGER.warning(f"Failed light: {e}:\r\n{function_data}")
self.device = device
self.device_manager = device_manager
self.entity_description = description

0 comments on commit caaa996

Please sign in to comment.