Renamed variables in Tuya (#57759)

This commit is contained in:
Franck Nijhof 2021-10-15 11:33:30 +02:00 committed by GitHub
parent b7c52d0485
commit b97d5a703c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 85 additions and 88 deletions

View file

@ -71,8 +71,8 @@ class TuyaEntity(Entity):
def __init__(self, device: TuyaDevice, device_manager: TuyaDeviceManager) -> None: def __init__(self, device: TuyaDevice, device_manager: TuyaDeviceManager) -> None:
"""Init TuyaHaEntity.""" """Init TuyaHaEntity."""
self._attr_unique_id = f"tuya.{device.id}" self._attr_unique_id = f"tuya.{device.id}"
self.tuya_device = device self.device = device
self.tuya_device_manager = device_manager self.device_manager = device_manager
@property @property
def name(self) -> str | None: def name(self) -> str | None:
@ -81,37 +81,35 @@ class TuyaEntity(Entity):
hasattr(self, "entity_description") hasattr(self, "entity_description")
and self.entity_description.name is not None and self.entity_description.name is not None
): ):
return f"{self.tuya_device.name} {self.entity_description.name}" return f"{self.device.name} {self.entity_description.name}"
return self.tuya_device.name return self.device.name
@property @property
def device_info(self) -> DeviceInfo: def device_info(self) -> DeviceInfo:
"""Return a device description for device registry.""" """Return a device description for device registry."""
return DeviceInfo( return DeviceInfo(
identifiers={(DOMAIN, self.tuya_device.id)}, identifiers={(DOMAIN, self.device.id)},
manufacturer="Tuya", manufacturer="Tuya",
name=self.tuya_device.name, name=self.device.name,
model=self.tuya_device.product_name, model=self.device.product_name,
) )
@property @property
def available(self) -> bool: def available(self) -> bool:
"""Return if the device is available.""" """Return if the device is available."""
return self.tuya_device.online return self.device.online
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Call when entity is added to hass.""" """Call when entity is added to hass."""
self.async_on_remove( self.async_on_remove(
async_dispatcher_connect( async_dispatcher_connect(
self.hass, self.hass,
f"{TUYA_HA_SIGNAL_UPDATE_ENTITY}_{self.tuya_device.id}", f"{TUYA_HA_SIGNAL_UPDATE_ENTITY}_{self.device.id}",
self.async_write_ha_state, self.async_write_ha_state,
) )
) )
def _send_command(self, commands: list[dict[str, Any]]) -> None: def _send_command(self, commands: list[dict[str, Any]]) -> None:
"""Send command to the device.""" """Send command to the device."""
_LOGGER.debug( _LOGGER.debug("Sending commands for device %s: %s", self.device.id, commands)
"Sending commands for device %s: %s", self.tuya_device.id, commands self.device_manager.send_commands(self.device.id, commands)
)
self.tuya_device_manager.send_commands(self.tuya_device.id, commands)

View file

@ -88,4 +88,4 @@ class TuyaBinarySensorEntity(TuyaEntity, BinarySensorEntity):
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if sensor is on.""" """Return true if sensor is on."""
return self.tuya_device.status.get(self.entity_description.key, False) return self.device.status.get(self.entity_description.key, False)

View file

@ -251,7 +251,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
): ):
self._current_humidity_dpcode = DPCode.HUMIDITY_CURRENT self._current_humidity_dpcode = DPCode.HUMIDITY_CURRENT
self._current_humidity_type = IntegerTypeData.from_json( self._current_humidity_type = IntegerTypeData.from_json(
self.tuya_device.status_range[DPCode.HUMIDITY_CURRENT].values self.device.status_range[DPCode.HUMIDITY_CURRENT].values
) )
# Determine dpcode to use for getting the current humidity # Determine dpcode to use for getting the current humidity
@ -261,7 +261,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
): ):
self._current_humidity_dpcode = DPCode.HUMIDITY_CURRENT self._current_humidity_dpcode = DPCode.HUMIDITY_CURRENT
self._current_humidity_type = IntegerTypeData.from_json( self._current_humidity_type = IntegerTypeData.from_json(
self.tuya_device.status_range[DPCode.HUMIDITY_CURRENT].values self.device.status_range[DPCode.HUMIDITY_CURRENT].values
) )
# Determine fan modes # Determine fan modes
@ -271,12 +271,12 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
): ):
self._attr_supported_features |= SUPPORT_FAN_MODE self._attr_supported_features |= SUPPORT_FAN_MODE
self._attr_fan_modes = EnumTypeData.from_json( self._attr_fan_modes = EnumTypeData.from_json(
self.tuya_device.status_range[DPCode.FAN_SPEED_ENUM].values self.device.status_range[DPCode.FAN_SPEED_ENUM].values
).range ).range
# Determine swing modes # Determine swing modes
if any( if any(
dpcode in self.tuya_device.function dpcode in self.device.function
for dpcode in ( for dpcode in (
DPCode.SHAKE, DPCode.SHAKE,
DPCode.SWING, DPCode.SWING,
@ -287,15 +287,15 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
self._attr_supported_features |= SUPPORT_SWING_MODE self._attr_supported_features |= SUPPORT_SWING_MODE
self._attr_swing_modes = [SWING_OFF] self._attr_swing_modes = [SWING_OFF]
if any( if any(
dpcode in self.tuya_device.function dpcode in self.device.function
for dpcode in (DPCode.SHAKE, DPCode.SWING) for dpcode in (DPCode.SHAKE, DPCode.SWING)
): ):
self._attr_swing_modes.append(SWING_ON) self._attr_swing_modes.append(SWING_ON)
if DPCode.SWITCH_HORIZONTAL in self.tuya_device.function: if DPCode.SWITCH_HORIZONTAL in self.device.function:
self._attr_swing_modes.append(SWING_HORIZONTAL) self._attr_swing_modes.append(SWING_HORIZONTAL)
if DPCode.SWITCH_VERTICAL in self.tuya_device.function: if DPCode.SWITCH_VERTICAL in self.device.function:
self._attr_swing_modes.append(SWING_VERTICAL) self._attr_swing_modes.append(SWING_VERTICAL)
def set_hvac_mode(self, hvac_mode: str) -> None: def set_hvac_mode(self, hvac_mode: str) -> None:
@ -379,7 +379,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
): ):
return None return None
temperature = self.tuya_device.status.get(self._current_temperature_dpcode) temperature = self.device.status.get(self._current_temperature_dpcode)
if temperature is None: if temperature is None:
return None return None
@ -391,7 +391,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
if self._current_humidity_dpcode is None or self._current_humidity_type is None: if self._current_humidity_dpcode is None or self._current_humidity_type is None:
return None return None
humidity = self.tuya_device.status.get(self._current_humidity_dpcode) humidity = self.device.status.get(self._current_humidity_dpcode)
if humidity is None: if humidity is None:
return None return None
@ -403,7 +403,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
if self._set_temperature_dpcode is None or self._set_temperature_type is None: if self._set_temperature_dpcode is None or self._set_temperature_type is None:
return None return None
temperature = self.tuya_device.status.get(self._set_temperature_dpcode) temperature = self.device.status.get(self._set_temperature_dpcode)
if temperature is None: if temperature is None:
return None return None
@ -415,7 +415,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
if self._set_humidity_dpcode is None or self._set_humidity_type is None: if self._set_humidity_dpcode is None or self._set_humidity_type is None:
return None return None
humidity = self.tuya_device.status.get(self._set_humidity_dpcode) humidity = self.device.status.get(self._set_humidity_dpcode)
if humidity is None: if humidity is None:
return None return None
@ -426,34 +426,33 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
"""Return hvac mode.""" """Return hvac mode."""
# If the switch off, hvac mode is off as well. Unless the switch # If the switch off, hvac mode is off as well. Unless the switch
# the switch is on or doesn't exists of course... # the switch is on or doesn't exists of course...
if not self.tuya_device.status.get(DPCode.SWITCH, True): if not self.device.status.get(DPCode.SWITCH, True):
return HVAC_MODE_OFF return HVAC_MODE_OFF
if DPCode.MODE not in self.tuya_device.function: if DPCode.MODE not in self.device.function:
if self.tuya_device.status.get(DPCode.SWITCH, False): if self.device.status.get(DPCode.SWITCH, False):
return self.entity_description.switch_only_hvac_mode return self.entity_description.switch_only_hvac_mode
return HVAC_MODE_OFF return HVAC_MODE_OFF
if self.tuya_device.status.get(DPCode.MODE) is not None: if self.device.status.get(DPCode.MODE) is not None:
return TUYA_HVAC_TO_HA[self.tuya_device.status[DPCode.MODE]] return TUYA_HVAC_TO_HA[self.device.status[DPCode.MODE]]
return HVAC_MODE_OFF return HVAC_MODE_OFF
@property @property
def fan_mode(self) -> str | None: def fan_mode(self) -> str | None:
"""Return fan mode.""" """Return fan mode."""
return self.tuya_device.status.get(DPCode.FAN_SPEED_ENUM) return self.device.status.get(DPCode.FAN_SPEED_ENUM)
@property @property
def swing_mode(self) -> str: def swing_mode(self) -> str:
"""Return swing mode.""" """Return swing mode."""
if any( if any(
self.tuya_device.status.get(dpcode) self.device.status.get(dpcode) for dpcode in (DPCode.SHAKE, DPCode.SWING)
for dpcode in (DPCode.SHAKE, DPCode.SWING)
): ):
return SWING_ON return SWING_ON
horizontal = self.tuya_device.status.get(DPCode.SWITCH_HORIZONTAL) horizontal = self.device.status.get(DPCode.SWITCH_HORIZONTAL)
vertical = self.tuya_device.status.get(DPCode.SWITCH_VERTICAL) vertical = self.device.status.get(DPCode.SWITCH_VERTICAL)
if horizontal and vertical: if horizontal and vertical:
return SWING_BOTH return SWING_BOTH
if horizontal: if horizontal:
@ -465,7 +464,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
def turn_on(self) -> None: def turn_on(self) -> None:
"""Turn the device on, retaining current HVAC (if supported).""" """Turn the device on, retaining current HVAC (if supported)."""
if DPCode.SWITCH in self.tuya_device.function: if DPCode.SWITCH in self.device.function:
self._send_command([{"code": DPCode.SWITCH, "value": True}]) self._send_command([{"code": DPCode.SWITCH, "value": True}])
return return
@ -478,7 +477,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
def turn_off(self) -> None: def turn_off(self) -> None:
"""Turn the device on, retaining current HVAC (if supported).""" """Turn the device on, retaining current HVAC (if supported)."""
if DPCode.SWITCH in self.tuya_device.function: if DPCode.SWITCH in self.device.function:
self._send_command([{"code": DPCode.SWITCH, "value": False}]) self._send_command([{"code": DPCode.SWITCH, "value": False}])
return return

View file

@ -65,9 +65,9 @@ class TuyaFanEntity(TuyaEntity, FanEntity):
super().__init__(device, device_manager) super().__init__(device, device_manager)
self.ha_preset_modes = [] self.ha_preset_modes = []
if DPCode.MODE in self.tuya_device.function: if DPCode.MODE in self.device.function:
self.ha_preset_modes = json.loads( self.ha_preset_modes = json.loads(
self.tuya_device.function[DPCode.MODE].values self.device.function[DPCode.MODE].values
).get("range", []) ).get("range", [])
# Air purifier fan can be controlled either via the ranged values or via the enum. # Air purifier fan can be controlled either via the ranged values or via the enum.
@ -76,18 +76,18 @@ class TuyaFanEntity(TuyaEntity, FanEntity):
# Range is used for e.g. Concept CA3000 # Range is used for e.g. Concept CA3000
self.air_purifier_speed_range_len = 0 self.air_purifier_speed_range_len = 0
self.air_purifier_speed_range_enum = [] self.air_purifier_speed_range_enum = []
if self.tuya_device.category == "kj" and ( if self.device.category == "kj" and (
DPCode.FAN_SPEED_ENUM in self.tuya_device.function DPCode.FAN_SPEED_ENUM in self.device.function
or DPCode.SPEED in self.tuya_device.function or DPCode.SPEED in self.device.function
): ):
if DPCode.FAN_SPEED_ENUM in self.tuya_device.function: if DPCode.FAN_SPEED_ENUM in self.device.function:
self.dp_code_speed_enum = DPCode.FAN_SPEED_ENUM self.dp_code_speed_enum = DPCode.FAN_SPEED_ENUM
else: else:
self.dp_code_speed_enum = DPCode.SPEED self.dp_code_speed_enum = DPCode.SPEED
data = json.loads( data = json.loads(self.device.function[self.dp_code_speed_enum].values).get(
self.tuya_device.function[self.dp_code_speed_enum].values "range"
).get("range") )
if data: if data:
self.air_purifier_speed_range_len = len(data) self.air_purifier_speed_range_len = len(data)
self.air_purifier_speed_range_enum = data self.air_purifier_speed_range_enum = data
@ -102,7 +102,7 @@ class TuyaFanEntity(TuyaEntity, FanEntity):
def set_percentage(self, percentage: int) -> None: def set_percentage(self, percentage: int) -> None:
"""Set the speed of the fan, as a percentage.""" """Set the speed of the fan, as a percentage."""
if self.tuya_device.category == "kj": if self.device.category == "kj":
value_in_range = percentage_to_ordered_list_item( value_in_range = percentage_to_ordered_list_item(
self.air_purifier_speed_range_enum, percentage self.air_purifier_speed_range_enum, percentage
) )
@ -140,19 +140,19 @@ class TuyaFanEntity(TuyaEntity, FanEntity):
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if fan is on.""" """Return true if fan is on."""
return self.tuya_device.status.get(DPCode.SWITCH, False) return self.device.status.get(DPCode.SWITCH, False)
@property @property
def current_direction(self) -> str: def current_direction(self) -> str:
"""Return the current direction of the fan.""" """Return the current direction of the fan."""
if self.tuya_device.status[DPCode.FAN_DIRECTION]: if self.device.status[DPCode.FAN_DIRECTION]:
return DIRECTION_FORWARD return DIRECTION_FORWARD
return DIRECTION_REVERSE return DIRECTION_REVERSE
@property @property
def oscillating(self) -> bool: def oscillating(self) -> bool:
"""Return true if the fan is oscillating.""" """Return true if the fan is oscillating."""
return self.tuya_device.status.get(DPCode.SWITCH_HORIZONTAL, False) return self.device.status.get(DPCode.SWITCH_HORIZONTAL, False)
@property @property
def preset_modes(self) -> list[str]: def preset_modes(self) -> list[str]:
@ -162,7 +162,7 @@ class TuyaFanEntity(TuyaEntity, FanEntity):
@property @property
def preset_mode(self) -> str: def preset_mode(self) -> str:
"""Return the current preset_mode.""" """Return the current preset_mode."""
return self.tuya_device.status[DPCode.MODE] return self.device.status[DPCode.MODE]
@property @property
def percentage(self) -> int | None: def percentage(self) -> int | None:
@ -171,24 +171,24 @@ class TuyaFanEntity(TuyaEntity, FanEntity):
return 0 return 0
if ( if (
self.tuya_device.category == "kj" self.device.category == "kj"
and self.air_purifier_speed_range_len > 1 and self.air_purifier_speed_range_len > 1
and not self.air_purifier_speed_range_enum and not self.air_purifier_speed_range_enum
and DPCode.FAN_SPEED_ENUM in self.tuya_device.status and DPCode.FAN_SPEED_ENUM in self.device.status
): ):
# if air-purifier speed enumeration is supported we will prefer it. # if air-purifier speed enumeration is supported we will prefer it.
return ordered_list_item_to_percentage( return ordered_list_item_to_percentage(
self.air_purifier_speed_range_enum, self.air_purifier_speed_range_enum,
self.tuya_device.status[DPCode.FAN_SPEED_ENUM], self.device.status[DPCode.FAN_SPEED_ENUM],
) )
# some type may not have the fan_speed_percent key # some type may not have the fan_speed_percent key
return self.tuya_device.status.get(DPCode.FAN_SPEED_PERCENT) return self.device.status.get(DPCode.FAN_SPEED_PERCENT)
@property @property
def speed_count(self) -> int: def speed_count(self) -> int:
"""Return the number of speeds the fan supports.""" """Return the number of speeds the fan supports."""
if self.tuya_device.category == "kj": if self.device.category == "kj":
return self.air_purifier_speed_range_len return self.air_purifier_speed_range_len
return super().speed_count return super().speed_count
@ -196,19 +196,19 @@ class TuyaFanEntity(TuyaEntity, FanEntity):
def supported_features(self): def supported_features(self):
"""Flag supported features.""" """Flag supported features."""
supports = 0 supports = 0
if DPCode.MODE in self.tuya_device.status: if DPCode.MODE in self.device.status:
supports |= SUPPORT_PRESET_MODE supports |= SUPPORT_PRESET_MODE
if DPCode.FAN_SPEED_PERCENT in self.tuya_device.status: if DPCode.FAN_SPEED_PERCENT in self.device.status:
supports |= SUPPORT_SET_SPEED supports |= SUPPORT_SET_SPEED
if DPCode.SWITCH_HORIZONTAL in self.tuya_device.status: if DPCode.SWITCH_HORIZONTAL in self.device.status:
supports |= SUPPORT_OSCILLATE supports |= SUPPORT_OSCILLATE
if DPCode.FAN_DIRECTION in self.tuya_device.status: if DPCode.FAN_DIRECTION in self.device.status:
supports |= SUPPORT_DIRECTION supports |= SUPPORT_DIRECTION
# Air Purifier specific # Air Purifier specific
if ( if (
DPCode.SPEED in self.tuya_device.status DPCode.SPEED in self.device.status
or DPCode.FAN_SPEED_ENUM in self.tuya_device.status or DPCode.FAN_SPEED_ENUM in self.device.status
): ):
supports |= SUPPORT_SET_SPEED supports |= SUPPORT_SET_SPEED
return supports return supports

View file

@ -109,7 +109,7 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if light is on.""" """Return true if light is on."""
return self.tuya_device.status.get(DPCode.SWITCH_LED, False) return self.device.status.get(DPCode.SWITCH_LED, False)
def turn_on(self, **kwargs: Any) -> None: def turn_on(self, **kwargs: Any) -> None:
"""Turn on or control the light.""" """Turn on or control the light."""
@ -118,8 +118,8 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
_LOGGER.debug("light kwargs-> %s; work_mode %s", kwargs, work_mode) _LOGGER.debug("light kwargs-> %s; work_mode %s", kwargs, work_mode)
if ( if (
DPCode.LIGHT in self.tuya_device.status DPCode.LIGHT in self.device.status
and DPCode.SWITCH_LED not in self.tuya_device.status and DPCode.SWITCH_LED not in self.device.status
): ):
commands += [{"code": DPCode.LIGHT, "value": True}] commands += [{"code": DPCode.LIGHT, "value": True}]
else: else:
@ -204,8 +204,8 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
def turn_off(self, **kwargs: Any) -> None: def turn_off(self, **kwargs: Any) -> None:
"""Instruct the light to turn off.""" """Instruct the light to turn off."""
if ( if (
DPCode.LIGHT in self.tuya_device.status DPCode.LIGHT in self.device.status
and DPCode.SWITCH_LED not in self.tuya_device.status and DPCode.SWITCH_LED not in self.device.status
): ):
commands = [{"code": DPCode.LIGHT, "value": False}] commands = [{"code": DPCode.LIGHT, "value": False}]
else: else:
@ -216,10 +216,10 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
def brightness(self) -> int | None: def brightness(self) -> int | None:
"""Return the brightness of the light.""" """Return the brightness of the light."""
old_range = self._tuya_brightness_range() old_range = self._tuya_brightness_range()
brightness = self.tuya_device.status.get(self.dp_code_bright, 0) brightness = self.device.status.get(self.dp_code_bright, 0)
if self._work_mode().startswith(WORK_MODE_COLOUR): if self._work_mode().startswith(WORK_MODE_COLOUR):
colour_json = self.tuya_device.status.get(self.dp_code_colour) colour_json = self.device.status.get(self.dp_code_colour)
if not colour_json: if not colour_json:
return None return None
colour_data = json.loads(colour_json) colour_data = json.loads(colour_json)
@ -230,9 +230,9 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
return int(self.remap(brightness, old_range[0], old_range[1], 0, 255)) return int(self.remap(brightness, old_range[0], old_range[1], 0, 255))
def _tuya_brightness_range(self) -> tuple[int, int]: def _tuya_brightness_range(self) -> tuple[int, int]:
if self.dp_code_bright not in self.tuya_device.status: if self.dp_code_bright not in self.device.status:
return 0, 255 return 0, 255
bright_item = self.tuya_device.function.get(self.dp_code_bright) bright_item = self.device.function.get(self.dp_code_bright)
if not bright_item: if not bright_item:
return 0, 255 return 0, 255
bright_value = json.loads(bright_item.values) bright_value = json.loads(bright_item.values)
@ -249,7 +249,7 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
@property @property
def hs_color(self) -> tuple[float, float] | None: def hs_color(self) -> tuple[float, float] | None:
"""Return the hs_color of the light.""" """Return the hs_color of the light."""
colour_json = self.tuya_device.status.get(self.dp_code_colour) colour_json = self.device.status.get(self.dp_code_colour)
if not colour_json: if not colour_json:
return None return None
colour_data = json.loads(colour_json) colour_data = json.loads(colour_json)
@ -266,7 +266,7 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
def color_temp(self) -> int: def color_temp(self) -> int:
"""Return the color_temp of the light.""" """Return the color_temp of the light."""
new_range = self._tuya_temp_range() new_range = self._tuya_temp_range()
tuya_color_temp = self.tuya_device.status.get(self.dp_code_temp, 0) tuya_color_temp = self.device.status.get(self.dp_code_temp, 0)
return ( return (
self.max_mireds self.max_mireds
- self.remap( - self.remap(
@ -290,7 +290,7 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
return MIREDS_MAX return MIREDS_MAX
def _tuya_temp_range(self) -> tuple[int, int]: def _tuya_temp_range(self) -> tuple[int, int]:
temp_item = self.tuya_device.function.get(self.dp_code_temp) temp_item = self.device.function.get(self.dp_code_temp)
if not temp_item: if not temp_item:
return 0, 255 return 0, 255
temp_value = json.loads(temp_item.values) temp_value = json.loads(temp_item.values)
@ -312,13 +312,13 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
return 0, 255 return 0, 255
def _tuya_hsv_function(self) -> dict[str, dict] | None: def _tuya_hsv_function(self) -> dict[str, dict] | None:
hsv_item = self.tuya_device.function.get(self.dp_code_colour) hsv_item = self.device.function.get(self.dp_code_colour)
if not hsv_item: if not hsv_item:
return None return None
hsv_data = json.loads(hsv_item.values) hsv_data = json.loads(hsv_item.values)
if hsv_data: if hsv_data:
return hsv_data return hsv_data
colour_json = self.tuya_device.status.get(self.dp_code_colour) colour_json = self.device.status.get(self.dp_code_colour)
if not colour_json: if not colour_json:
return None return None
colour_data = json.loads(colour_json) colour_data = json.loads(colour_json)
@ -331,30 +331,30 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
return DEFAULT_HSV return DEFAULT_HSV
def _work_mode(self) -> str: def _work_mode(self) -> str:
return self.tuya_device.status.get(DPCode.WORK_MODE, "") return self.device.status.get(DPCode.WORK_MODE, "")
def _get_hsv(self) -> dict[str, int]: def _get_hsv(self) -> dict[str, int]:
if ( if (
self.dp_code_colour not in self.tuya_device.status self.dp_code_colour not in self.device.status
or len(self.tuya_device.status[self.dp_code_colour]) == 0 or len(self.device.status[self.dp_code_colour]) == 0
): ):
return {"h": 0, "s": 0, "v": 0} return {"h": 0, "s": 0, "v": 0}
return json.loads(self.tuya_device.status[self.dp_code_colour]) return json.loads(self.device.status[self.dp_code_colour])
@property @property
def supported_color_modes(self) -> set[str] | None: def supported_color_modes(self) -> set[str] | None:
"""Flag supported color modes.""" """Flag supported color modes."""
color_modes = [COLOR_MODE_ONOFF] color_modes = [COLOR_MODE_ONOFF]
if self.dp_code_bright in self.tuya_device.status: if self.dp_code_bright in self.device.status:
color_modes.append(COLOR_MODE_BRIGHTNESS) color_modes.append(COLOR_MODE_BRIGHTNESS)
if self.dp_code_temp in self.tuya_device.status: if self.dp_code_temp in self.device.status:
color_modes.append(COLOR_MODE_COLOR_TEMP) color_modes.append(COLOR_MODE_COLOR_TEMP)
if ( if (
self.dp_code_colour in self.tuya_device.status self.dp_code_colour in self.device.status
and len(self.tuya_device.status[self.dp_code_colour]) > 0 and len(self.device.status[self.dp_code_colour]) > 0
): ):
color_modes.append(COLOR_MODE_HS) color_modes.append(COLOR_MODE_HS)
return set(color_modes) return set(color_modes)

View file

@ -121,7 +121,7 @@ class TuyaNumberEntity(TuyaEntity, NumberEntity):
return None return None
# Raw value # Raw value
value = self.tuya_device.status.get(self.entity_description.key) value = self.device.status.get(self.entity_description.key)
# Scale integer/float value # Scale integer/float value
if value and isinstance(self._type_data, IntegerTypeData): if value and isinstance(self._type_data, IntegerTypeData):

View file

@ -105,7 +105,7 @@ class TuyaSelectEntity(TuyaEntity, SelectEntity):
def current_option(self) -> str | None: def current_option(self) -> str | None:
"""Return the selected entity option to represent the entity state.""" """Return the selected entity option to represent the entity state."""
# Raw value # Raw value
value = self.tuya_device.status.get(self.entity_description.key) value = self.device.status.get(self.entity_description.key)
if value is None or value not in self._attr_options: if value is None or value not in self._attr_options:
return None return None

View file

@ -161,7 +161,7 @@ class TuyaSensorEntity(TuyaEntity, SensorEntity):
return None return None
# Raw value # Raw value
value = self.tuya_device.status.get(self.entity_description.key) value = self.device.status.get(self.entity_description.key)
if value is None: if value is None:
return None return None

View file

@ -312,7 +312,7 @@ class TuyaSwitchEntity(TuyaEntity, SwitchEntity):
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if switch is on.""" """Return true if switch is on."""
return self.tuya_device.status.get(self.entity_description.key, False) return self.device.status.get(self.entity_description.key, False)
def turn_on(self, **kwargs: Any) -> None: def turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on.""" """Turn the switch on."""