Migrate Tuya integration to new sharing SDK (#109155)

* Scan QR code to log in And Migrate Tuya integration to new sharing SDK (#104767)

* Remove non-opt-in/out reporting

* Improve setup, fix unload

* Cleanup token listner, remove logging of sensitive data

* Collection of fixes after extensive testing

* Tests happy user config flow path

* Test unhappy paths

* Add reauth

* Fix translation key

* Prettier manifest

* Ruff format

* Cleanup of const

* Process review comments

* Adjust update token handling

---------

Co-authored-by: melo <411787243@qq.com>
This commit is contained in:
Franck Nijhof 2024-01-31 03:22:22 +01:00 committed by GitHub
parent 712ba2fdca
commit 82e1ed43f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 829 additions and 708 deletions

View file

@ -3,8 +3,8 @@ from __future__ import annotations
from dataclasses import dataclass
from tuya_iot import TuyaDevice, TuyaDeviceManager
from tuya_iot.device import TuyaDeviceStatusRange
from tuya_sharing import CustomerDevice, Manager
from tuya_sharing.device import DeviceStatusRange
from homeassistant.components.sensor import (
SensorDeviceClass,
@ -1112,19 +1112,17 @@ async def async_setup_entry(
"""Discover and add a discovered Tuya sensor."""
entities: list[TuyaSensorEntity] = []
for device_id in device_ids:
device = hass_data.device_manager.device_map[device_id]
device = hass_data.manager.device_map[device_id]
if descriptions := SENSORS.get(device.category):
for description in descriptions:
if description.key in device.status:
entities.append(
TuyaSensorEntity(
device, hass_data.device_manager, description
)
TuyaSensorEntity(device, hass_data.manager, description)
)
async_add_entities(entities)
async_discover_device([*hass_data.device_manager.device_map])
async_discover_device([*hass_data.manager.device_map])
entry.async_on_unload(
async_dispatcher_connect(hass, TUYA_DISCOVERY_NEW, async_discover_device)
@ -1136,15 +1134,15 @@ class TuyaSensorEntity(TuyaEntity, SensorEntity):
entity_description: TuyaSensorEntityDescription
_status_range: TuyaDeviceStatusRange | None = None
_status_range: DeviceStatusRange | None = None
_type: DPType | None = None
_type_data: IntegerTypeData | EnumTypeData | None = None
_uom: UnitOfMeasurement | None = None
def __init__(
self,
device: TuyaDevice,
device_manager: TuyaDeviceManager,
device: CustomerDevice,
device_manager: Manager,
description: TuyaSensorEntityDescription,
) -> None:
"""Init Tuya sensor."""