diff --git a/homeassistant/components/tuya/__init__.py b/homeassistant/components/tuya/__init__.py index ceb8f056c2220..2d8c28a33a61a 100644 --- a/homeassistant/components/tuya/__init__.py +++ b/homeassistant/components/tuya/__init__.py @@ -35,6 +35,8 @@ # Suppress logs from the library, it logs unneeded on error logging.getLogger("tuya_sharing").setLevel(logging.CRITICAL) +TuyaConfigEntry = ConfigEntry["HomeAssistantTuyaData"] + class HomeAssistantTuyaData(NamedTuple): """Tuya data stored in the Home Assistant data object.""" @@ -43,7 +45,7 @@ class HomeAssistantTuyaData(NamedTuple): listener: SharingDeviceListener -async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_setup_entry(hass: HomeAssistant, entry: TuyaConfigEntry) -> bool: """Async setup hass config entry.""" if CONF_APP_TYPE in entry.data: raise ConfigEntryAuthFailed("Authentication failed. Please re-authenticate.") @@ -73,9 +75,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: raise # Connection is successful, store the manager & listener - hass.data.setdefault(DOMAIN, {})[entry.entry_id] = HomeAssistantTuyaData( - manager=manager, listener=listener - ) + entry.runtime_data = HomeAssistantTuyaData(manager=manager, listener=listener) # Cleanup device registry await cleanup_device_registry(hass, manager) @@ -108,18 +108,17 @@ async def cleanup_device_registry(hass: HomeAssistant, device_manager: Manager) break -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: TuyaConfigEntry) -> bool: """Unloading the Tuya platforms.""" if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): - tuya: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + tuya = entry.runtime_data if tuya.manager.mq is not None: tuya.manager.mq.stop() tuya.manager.remove_device_listener(tuya.listener) - del hass.data[DOMAIN][entry.entry_id] return unload_ok -async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: +async def async_remove_entry(hass: HomeAssistant, entry: TuyaConfigEntry) -> None: """Remove a config entry. This will revoke the credentials from Tuya. @@ -184,7 +183,7 @@ class TokenListener(SharingTokenListener): def __init__( self, hass: HomeAssistant, - entry: ConfigEntry, + entry: TuyaConfigEntry, ) -> None: """Init TokenListener.""" self.hass = hass diff --git a/homeassistant/components/tuya/alarm_control_panel.py b/homeassistant/components/tuya/alarm_control_panel.py index 59075cf00cde9..868f6634bc94a 100644 --- a/homeassistant/components/tuya/alarm_control_panel.py +++ b/homeassistant/components/tuya/alarm_control_panel.py @@ -11,7 +11,6 @@ AlarmControlPanelEntityDescription, AlarmControlPanelEntityFeature, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, @@ -22,9 +21,9 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType +from .const import TUYA_DISCOVERY_NEW, DPCode, DPType class Mode(StrEnum): @@ -59,10 +58,10 @@ class Mode(StrEnum): async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Tuya alarm dynamically through Tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: diff --git a/homeassistant/components/tuya/binary_sensor.py b/homeassistant/components/tuya/binary_sensor.py index c9f4734a7df83..b992c24d07df9 100644 --- a/homeassistant/components/tuya/binary_sensor.py +++ b/homeassistant/components/tuya/binary_sensor.py @@ -11,15 +11,14 @@ BinarySensorEntity, 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_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode +from .const import TUYA_DISCOVERY_NEW, DPCode @dataclass(frozen=True) @@ -338,10 +337,10 @@ class TuyaBinarySensorEntityDescription(BinarySensorEntityDescription): async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Tuya binary sensor dynamically through Tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: diff --git a/homeassistant/components/tuya/button.py b/homeassistant/components/tuya/button.py index a170ddb09e9d3..f62bba928b41e 100644 --- a/homeassistant/components/tuya/button.py +++ b/homeassistant/components/tuya/button.py @@ -5,15 +5,14 @@ from tuya_sharing import CustomerDevice, Manager 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_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode +from .const import TUYA_DISCOVERY_NEW, DPCode # All descriptions can be found here. # https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq @@ -59,10 +58,10 @@ async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Tuya buttons dynamically through Tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: diff --git a/homeassistant/components/tuya/camera.py b/homeassistant/components/tuya/camera.py index 79f8c1b169222..f3913611b07bb 100644 --- a/homeassistant/components/tuya/camera.py +++ b/homeassistant/components/tuya/camera.py @@ -6,14 +6,13 @@ from homeassistant.components import ffmpeg from homeassistant.components.camera import Camera as CameraEntity, CameraEntityFeature -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode +from .const import TUYA_DISCOVERY_NEW, DPCode # All descriptions can be found here: # https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq @@ -25,10 +24,10 @@ async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Tuya cameras dynamically through Tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: diff --git a/homeassistant/components/tuya/climate.py b/homeassistant/components/tuya/climate.py index 3be80193beb31..d47c71532a486 100644 --- a/homeassistant/components/tuya/climate.py +++ b/homeassistant/components/tuya/climate.py @@ -18,15 +18,14 @@ ClimateEntityFeature, HVACMode, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import IntegerTypeData, TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType +from .const import TUYA_DISCOVERY_NEW, DPCode, DPType TUYA_HVAC_TO_HA = { "auto": HVACMode.HEAT_COOL, @@ -82,10 +81,10 @@ class TuyaClimateEntityDescription(ClimateEntityDescription): async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Tuya climate dynamically through Tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: diff --git a/homeassistant/components/tuya/cover.py b/homeassistant/components/tuya/cover.py index 7dc54888ac471..2e81529f9743c 100644 --- a/homeassistant/components/tuya/cover.py +++ b/homeassistant/components/tuya/cover.py @@ -15,14 +15,13 @@ CoverEntityDescription, CoverEntityFeature, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import IntegerTypeData, TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType +from .const import TUYA_DISCOVERY_NEW, DPCode, DPType @dataclass(frozen=True) @@ -143,10 +142,10 @@ class TuyaCoverEntityDescription(CoverEntityDescription): async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Tuya cover dynamically through Tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: diff --git a/homeassistant/components/tuya/diagnostics.py b/homeassistant/components/tuya/diagnostics.py index f817261c8fc29..9675b215ce208 100644 --- a/homeassistant/components/tuya/diagnostics.py +++ b/homeassistant/components/tuya/diagnostics.py @@ -9,25 +9,24 @@ from tuya_sharing import CustomerDevice from homeassistant.components.diagnostics import REDACTED -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers.device_registry import DeviceEntry from homeassistant.util import dt as dt_util -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .const import DOMAIN, DPCode async def async_get_config_entry_diagnostics( - hass: HomeAssistant, entry: ConfigEntry + hass: HomeAssistant, entry: TuyaConfigEntry ) -> dict[str, Any]: """Return diagnostics for a config entry.""" return _async_get_diagnostics(hass, entry) async def async_get_device_diagnostics( - hass: HomeAssistant, entry: ConfigEntry, device: DeviceEntry + hass: HomeAssistant, entry: TuyaConfigEntry, device: DeviceEntry ) -> dict[str, Any]: """Return diagnostics for a device entry.""" return _async_get_diagnostics(hass, entry, device) @@ -36,11 +35,11 @@ async def async_get_device_diagnostics( @callback def _async_get_diagnostics( hass: HomeAssistant, - entry: ConfigEntry, + entry: TuyaConfigEntry, device: DeviceEntry | None = None, ) -> dict[str, Any]: """Return diagnostics for a config entry.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data mqtt_connected = None if hass_data.manager.mq.client: diff --git a/homeassistant/components/tuya/fan.py b/homeassistant/components/tuya/fan.py index 3925da1d50744..d4c19f6b55a38 100644 --- a/homeassistant/components/tuya/fan.py +++ b/homeassistant/components/tuya/fan.py @@ -12,7 +12,6 @@ FanEntity, FanEntityFeature, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -21,9 +20,9 @@ percentage_to_ordered_list_item, ) -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import EnumTypeData, IntegerTypeData, TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType +from .const import TUYA_DISCOVERY_NEW, DPCode, DPType TUYA_SUPPORT_TYPE = { "fs", # Fan @@ -35,10 +34,10 @@ async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up tuya fan dynamically through tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: diff --git a/homeassistant/components/tuya/humidifier.py b/homeassistant/components/tuya/humidifier.py index 927aaf8a74ad7..3d16b0dfbbbfb 100644 --- a/homeassistant/components/tuya/humidifier.py +++ b/homeassistant/components/tuya/humidifier.py @@ -12,14 +12,13 @@ HumidifierEntityDescription, HumidifierEntityFeature, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import IntegerTypeData, TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType +from .const import TUYA_DISCOVERY_NEW, DPCode, DPType @dataclass(frozen=True) @@ -56,10 +55,10 @@ class TuyaHumidifierEntityDescription(HumidifierEntityDescription): async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Tuya (de)humidifier dynamically through Tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: diff --git a/homeassistant/components/tuya/light.py b/homeassistant/components/tuya/light.py index d898e837d8ecc..3533dabf92a9c 100644 --- a/homeassistant/components/tuya/light.py +++ b/homeassistant/components/tuya/light.py @@ -17,15 +17,14 @@ LightEntityDescription, filter_supported_color_modes, ) -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_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import IntegerTypeData, TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType, WorkMode +from .const import TUYA_DISCOVERY_NEW, DPCode, DPType, WorkMode from .util import remap_value @@ -409,10 +408,10 @@ def brightness(self) -> int: async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up tuya light dynamically through tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]): diff --git a/homeassistant/components/tuya/number.py b/homeassistant/components/tuya/number.py index 2be7deef89f21..424450c7fec28 100644 --- a/homeassistant/components/tuya/number.py +++ b/homeassistant/components/tuya/number.py @@ -9,13 +9,12 @@ NumberEntity, NumberEntityDescription, ) -from homeassistant.config_entries import ConfigEntry 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_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import IntegerTypeData, TuyaEntity from .const import DEVICE_CLASS_UNITS, DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType @@ -282,10 +281,10 @@ async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Tuya number dynamically through Tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: diff --git a/homeassistant/components/tuya/scene.py b/homeassistant/components/tuya/scene.py index dcc1aae1fbab5..1465724faac09 100644 --- a/homeassistant/components/tuya/scene.py +++ b/homeassistant/components/tuya/scene.py @@ -7,20 +7,19 @@ from tuya_sharing import Manager, SharingScene from homeassistant.components.scene import Scene -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .const import DOMAIN async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Tuya scenes.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data scenes = await hass.async_add_executor_job(hass_data.manager.query_scenes) async_add_entities(TuyaSceneEntity(hass_data.manager, scene) for scene in scenes) diff --git a/homeassistant/components/tuya/select.py b/homeassistant/components/tuya/select.py index 6e128bfdcc440..111b9e40918a1 100644 --- a/homeassistant/components/tuya/select.py +++ b/homeassistant/components/tuya/select.py @@ -5,15 +5,14 @@ from tuya_sharing import CustomerDevice, Manager 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_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType +from .const import TUYA_DISCOVERY_NEW, DPCode, DPType # All descriptions can be found here. Mostly the Enum data types in the # default instructions set of each category end up being a select. @@ -320,10 +319,10 @@ async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Tuya select dynamically through Tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: diff --git a/homeassistant/components/tuya/sensor.py b/homeassistant/components/tuya/sensor.py index df11840931d07..9382059471d39 100644 --- a/homeassistant/components/tuya/sensor.py +++ b/homeassistant/components/tuya/sensor.py @@ -13,7 +13,6 @@ SensorEntityDescription, SensorStateClass, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( PERCENTAGE, EntityCategory, @@ -27,7 +26,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import ElectricityTypeData, EnumTypeData, IntegerTypeData, TuyaEntity from .const import ( DEVICE_CLASS_UNITS, @@ -1075,10 +1074,10 @@ class TuyaSensorEntityDescription(SensorEntityDescription): async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Tuya sensor dynamically through Tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: diff --git a/homeassistant/components/tuya/siren.py b/homeassistant/components/tuya/siren.py index 04473e44e221b..683705c6546dd 100644 --- a/homeassistant/components/tuya/siren.py +++ b/homeassistant/components/tuya/siren.py @@ -11,14 +11,13 @@ SirenEntityDescription, SirenEntityFeature, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode +from .const import TUYA_DISCOVERY_NEW, DPCode # All descriptions can be found here: # https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq @@ -48,10 +47,10 @@ async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Tuya siren dynamically through Tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: diff --git a/homeassistant/components/tuya/switch.py b/homeassistant/components/tuya/switch.py index 36debaeadde79..b33852870a879 100644 --- a/homeassistant/components/tuya/switch.py +++ b/homeassistant/components/tuya/switch.py @@ -11,15 +11,14 @@ SwitchEntity, SwitchEntityDescription, ) -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_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode +from .const import TUYA_DISCOVERY_NEW, DPCode # All descriptions can be found here. Mostly the Boolean data types in the # default instruction set of each category end up being a Switch. @@ -660,10 +659,10 @@ async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up tuya sensors dynamically through tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: diff --git a/homeassistant/components/tuya/vacuum.py b/homeassistant/components/tuya/vacuum.py index 6774aaac8a1ee..360d6d4f5c31e 100644 --- a/homeassistant/components/tuya/vacuum.py +++ b/homeassistant/components/tuya/vacuum.py @@ -13,15 +13,14 @@ StateVacuumEntity, VacuumEntityFeature, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import STATE_IDLE, STATE_PAUSED from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import HomeAssistantTuyaData +from . import TuyaConfigEntry from .base import EnumTypeData, IntegerTypeData, TuyaEntity -from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType +from .const import TUYA_DISCOVERY_NEW, DPCode, DPType TUYA_MODE_RETURN_HOME = "chargego" TUYA_STATUS_TO_HA = { @@ -52,10 +51,10 @@ async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up Tuya vacuum dynamically through Tuya discovery.""" - hass_data: HomeAssistantTuyaData = hass.data[DOMAIN][entry.entry_id] + hass_data = entry.runtime_data @callback def async_discover_device(device_ids: list[str]) -> None: