Skip to content

Commit

Permalink
Merge pull request #8 from dougiteixeira/2023.6
Browse files Browse the repository at this point in the history
Updates to work with the latest version of Home Assistant (2023.6).
  • Loading branch information
dougiteixeira authored Jun 11, 2023
2 parents 2ce1b99 + d3b8b45 commit 2509c85
Show file tree
Hide file tree
Showing 13 changed files with 510 additions and 472 deletions.
2 changes: 1 addition & 1 deletion custom_components/tuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async def cleanup_device_registry(
device_registry = dr.async_get(hass)
for dev_id, device_entry in list(device_registry.devices.items()):
for item in device_entry.identifiers:
if DOMAIN == item[0] and item[1] not in device_manager.device_map:
if item[0] == DOMAIN and item[1] not in device_manager.device_map:
device_registry.async_remove_device(dev_id)
break

Expand Down
5 changes: 3 additions & 2 deletions custom_components/tuya/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Any, Literal, overload

from tuya_iot import TuyaDevice, TuyaDeviceManager
from typing_extensions import Self

from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo, Entity
Expand Down Expand Up @@ -112,12 +113,12 @@ class ElectricityTypeData:
voltage: str | None = None

@classmethod
def from_json(cls, data: str) -> ElectricityTypeData:
def from_json(cls, data: str) -> Self:
"""Load JSON string and return a ElectricityTypeData object."""
return cls(**json.loads(data.lower()))

@classmethod
def from_raw(cls, data: str) -> ElectricityTypeData:
def from_raw(cls, data: str) -> Self:
"""Decode base64 string and return a ElectricityTypeData object."""
raw = base64.b64decode(data)
voltage = struct.unpack(">H", raw[0:2])[0] / 10.0
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tuya/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
BinarySensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import HomeAssistantTuyaData
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tuya/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import HomeAssistantTuyaData
Expand Down
34 changes: 23 additions & 11 deletions custom_components/tuya/light.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Support for the Tuya lights."""
from __future__ import annotations

from dataclasses import dataclass
from dataclasses import dataclass, field
import json
from typing import Any, cast

Expand All @@ -16,9 +16,9 @@
LightEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import HomeAssistantTuyaData
Expand Down Expand Up @@ -59,7 +59,9 @@ class TuyaLightEntityDescription(LightEntityDescription):
color_data: DPCode | tuple[DPCode, ...] | None = None
color_mode: DPCode | None = None
color_temp: DPCode | tuple[DPCode, ...] | None = None
default_color_type: ColorTypeData = DEFAULT_COLOR_TYPE_DATA
default_color_type: ColorTypeData = field(
default_factory=lambda: DEFAULT_COLOR_TYPE_DATA
)


LIGHTS: dict[str, tuple[TuyaLightEntityDescription, ...]] = {
Expand Down Expand Up @@ -169,6 +171,15 @@ class TuyaLightEntityDescription(LightEntityDescription):
entity_category=EntityCategory.CONFIG,
),
),
# Air Purifier
# https://developer.tuya.com/en/docs/iot/f?id=K9gf46h2s6dzm
"kj": (
TuyaLightEntityDescription(
key=DPCode.LIGHT,
name="Backlight",
entity_category=EntityCategory.CONFIG,
),
),
# Air conditioner
# https://developer.tuya.com/en/docs/iot/categorykt?id=Kaiuz0z71ov2n
"kt": (
Expand Down Expand Up @@ -219,7 +230,7 @@ class TuyaLightEntityDescription(LightEntityDescription):
),
TuyaLightEntityDescription(
key=DPCode.BASIC_INDICATOR,
name="Indicator Light",
name="Indicator light",
entity_category=EntityCategory.CONFIG,
),
),
Expand Down Expand Up @@ -497,9 +508,14 @@ def turn_on(self, **kwargs: Any) -> None:
),
},
]
elif self._color_data_type and (

if self._color_data_type and (
ATTR_HS_COLOR in kwargs
or (ATTR_BRIGHTNESS in kwargs and self.color_mode == ColorMode.HS)
or (
ATTR_BRIGHTNESS in kwargs
and self.color_mode == ColorMode.HS
and ATTR_COLOR_TEMP not in kwargs
)
):
if self._color_mode_dpcode:
commands += [
Expand Down Expand Up @@ -540,11 +556,7 @@ def turn_on(self, **kwargs: Any) -> None:
},
]

if (
ATTR_BRIGHTNESS in kwargs
and self.color_mode != ColorMode.HS
and self._brightness
):
elif ATTR_BRIGHTNESS in kwargs and self._brightness:
brightness = kwargs[ATTR_BRIGHTNESS]

# If there is a min/max value, the brightness is actually limited.
Expand Down
46 changes: 34 additions & 12 deletions custom_components/tuya/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,44 @@
"config_flow": true,
"dependencies": ["ffmpeg"],
"dhcp": [
{ "macaddress": "105A17*" },
{ "macaddress": "10D561*" },
{ "macaddress": "1869D8*" },
{ "macaddress": "381F8D*" },
{ "macaddress": "508A06*" },
{ "macaddress": "68572D*" },
{ "macaddress": "708976*" },
{ "macaddress": "7CF666*" },
{ "macaddress": "84E342*" },
{ "macaddress": "D4A651*" },
{ "macaddress": "D81F12*" }
{
"macaddress": "105A17*"
},
{
"macaddress": "10D561*"
},
{
"macaddress": "1869D8*"
},
{
"macaddress": "381F8D*"
},
{
"macaddress": "508A06*"
},
{
"macaddress": "68572D*"
},
{
"macaddress": "708976*"
},
{
"macaddress": "7CF666*"
},
{
"macaddress": "84E342*"
},
{
"macaddress": "D4A651*"
},
{
"macaddress": "D81F12*"
}
],
"documentation": "https://www.home-assistant.io/integrations/tuya",
"integration_type": "hub",
"iot_class": "cloud_push",
"loggers": ["tuya_iot"],
"requirements": ["tuya-iot-py-sdk==0.6.6"],
"version": "24012023.001"
"version": "11062023.001"
}
4 changes: 1 addition & 3 deletions custom_components/tuya/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
NumberEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, UnitOfTime
from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfTime
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import HomeAssistantTuyaData
Expand Down Expand Up @@ -412,7 +411,6 @@ def __init__(
and not self.device_class.startswith(DOMAIN)
and description.native_unit_of_measurement is None
):

# We cannot have a device class, if the UOM isn't set or the
# device class cannot be found in the validation mapping.
if (
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tuya/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import HomeAssistantTuyaData
Expand Down
4 changes: 2 additions & 2 deletions custom_components/tuya/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
PERCENTAGE,
EntityCategory,
UnitOfElectricCurrent,
UnitOfElectricPotential,
UnitOfPower,
UnitOfTime,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType

Expand Down Expand Up @@ -991,7 +991,7 @@ class TuyaSensorEntityDescription(SensorEntityDescription):
),
TuyaSensorEntityDescription(
key=DPCode.TOTAL_CLEAN_AREA,
name="Total Cleaning Area",
name="Total cleaning area",
icon="mdi:texture-box",
state_class=SensorStateClass.TOTAL_INCREASING,
),
Expand Down
Loading

0 comments on commit 2509c85

Please sign in to comment.