from __future__ import annotations """ * SPDX-FileCopyrightText: Copyright 2024 LG Electronics Inc. * SPDX-License-Identifier: Apache-2.0 """ from dataclasses import dataclass from typing import Any from .connect_device import ConnectBaseDevice, ConnectDeviceProfile from .const import Property, Resource class AirPurifierProfile(ConnectDeviceProfile): def __init__(self, profile: dict[str, Any]): super().__init__( profile=profile, resource_map={ "airPurifierJobMode": Resource.AIR_PURIFIER_JOB_MODE, "operation": Resource.OPERATION, "timer": Resource.TIMER, "sleepTimer": Resource.SLEEP_TIMER, "airFlow": Resource.AIR_FLOW, "airQualitySensor": Resource.AIR_QUALITY_SENSOR, "filterInfo": Resource.FILTER_INFO, }, profile_map={ "airPurifierJobMode": { "currentJobMode": Property.CURRENT_JOB_MODE, "personalizationMode": Property.PERSONALIZATION_MODE, }, "operation": {"airPurifierOperationMode": Property.AIR_PURIFIER_OPERATION_MODE}, "timer": { "absoluteHourToStart": Property.ABSOLUTE_HOUR_TO_START, "absoluteMinuteToStart": Property.ABSOLUTE_MINUTE_TO_START, "absoluteHourToStop": Property.ABSOLUTE_HOUR_TO_STOP, "absoluteMinuteToStop": Property.ABSOLUTE_MINUTE_TO_STOP, }, "sleepTimer": { "relativeHourToStop": Property.SLEEP_TIMER_RELATIVE_HOUR_TO_STOP, "relativeMinuteToStop": Property.SLEEP_TIMER_RELATIVE_MINUTE_TO_STOP, }, "airFlow": { self._get_preferred_property_key( profile, "airFlow", ["windStrengthDetail", "windStrength"] ): Property.WIND_STRENGTH, }, "airQualitySensor": { "monitoringEnabled": Property.MONITORING_ENABLED, "PM1": Property.PM1, "PM1Level": Property.PM1_LEVEL, "PM2": Property.PM2, "PM2Level": Property.PM2_LEVEL, "PM10": Property.PM10, "PM10Level": Property.PM10_LEVEL, "odor": Property.ODOR, "odorLevel": Property.ODOR_LEVEL, "humidity": Property.HUMIDITY, "totalPollution": Property.TOTAL_POLLUTION, "totalPollutionLevel": Property.TOTAL_POLLUTION_LEVEL, }, "filterInfo": { "topFilterRemainPercent": Property.TOP_FILTER_REMAIN_PERCENT, "filterRemainPercent": Property.FILTER_REMAIN_PERCENT, }, }, ) @dataclass class AirPurifierDevice(ConnectBaseDevice): PROFILE_TYPE = AirPurifierProfile _CUSTOM_SET_PROPERTY_NAME = { Property.ABSOLUTE_HOUR_TO_START: "absolute_time_to_start", Property.ABSOLUTE_MINUTE_TO_START: "absolute_time_to_start", Property.ABSOLUTE_HOUR_TO_STOP: "absolute_time_to_stop", Property.ABSOLUTE_MINUTE_TO_STOP: "absolute_time_to_stop", Property.SLEEP_TIMER_RELATIVE_HOUR_TO_STOP: "sleep_timer_relative_time_to_stop", Property.SLEEP_TIMER_RELATIVE_MINUTE_TO_STOP: "sleep_timer_relative_time_to_stop", } @property def profiles(self) -> AirPurifierProfile: return self._profiles @profiles.setter def profiles(self, profiles: AirPurifierProfile): self._profiles = profiles async def set_current_job_mode(self, job_mode: str) -> dict | None: return await self.do_enum_attribute_command(Property.CURRENT_JOB_MODE, job_mode) async def set_air_purifier_operation_mode(self, operation_mode: str) -> dict | None: return await self.do_enum_attribute_command(Property.AIR_PURIFIER_OPERATION_MODE, operation_mode) async def set_absolute_time_to_start(self, hour: int, minute: int) -> dict | None: return await self.do_multi_attribute_command( { Property.ABSOLUTE_HOUR_TO_START: hour, Property.ABSOLUTE_MINUTE_TO_START: minute, } ) async def set_absolute_time_to_stop(self, hour: int, minute: int) -> dict | None: return await self.do_multi_attribute_command( { Property.ABSOLUTE_HOUR_TO_STOP: hour, Property.ABSOLUTE_MINUTE_TO_STOP: minute, } ) async def set_sleep_timer_relative_time_to_stop(self, hour: int) -> dict | None: return await self.do_attribute_command(Property.SLEEP_TIMER_RELATIVE_HOUR_TO_STOP, hour) async def set_wind_strength(self, wind_strength: str) -> dict | None: return await self.do_enum_attribute_command(Property.WIND_STRENGTH, wind_strength)