From bc6f22c0cc8ca1ca098e4ad42b7bb07a0c77a9e5 Mon Sep 17 00:00:00 2001 From: Dinculescu Date: Sat, 4 May 2024 13:15:19 +0100 Subject: [PATCH] tapo-py: Reorganize the types --- CHANGELOG.md | 4 + tapo-py/examples/tapo_l530.py | 3 +- tapo-py/examples/tapo_p110.py | 3 +- tapo-py/src/lib.rs | 61 +++++++-- tapo-py/tapo-py/tapo/__init__.pyi | 2 +- tapo-py/tapo-py/tapo/color_light_handler.pyi | 122 +----------------- .../tapo-py/tapo/generic_device_handler.pyi | 39 +----- tapo-py/tapo-py/tapo/hub_handler.pyi | 52 ++------ tapo-py/tapo-py/tapo/light_handler.pyi | 57 +------- .../tapo/plug_energy_monitoring_handler.pyi | 87 ++----------- tapo-py/tapo-py/tapo/plug_handler.pyi | 55 +------- tapo-py/tapo-py/tapo/requests/__init__.py | 0 tapo-py/tapo-py/tapo/requests/__init__.pyi | 3 + tapo-py/tapo-py/tapo/requests/color.pyi | 46 +++++++ .../tapo/requests/energy_data_interval.pyi | 15 +++ .../tapo/requests/set_device_info/__init__.py | 0 .../requests/set_device_info/__init__.pyi | 1 + .../requests/set_device_info/color_light.pyi | 57 ++++++++ tapo-py/tapo-py/tapo/responses/__init__.pyi | 7 + .../tapo/responses/current_power_result.pyi | 12 ++ .../tapo-py/tapo/responses/default_state.pyi | 19 +++ .../responses/device_info_result/__init__.py | 0 .../responses/device_info_result/__init__.pyi | 5 + .../device_info_result/color_light_result.pyi | 64 +++++++++ .../device_info_result/generic_result.pyi | 38 ++++++ .../device_info_result/hub_result.pyi | 39 ++++++ .../device_info_result/light_result.pyi | 51 ++++++++ .../device_info_result/plug_result.pyi | 55 ++++++++ .../device_usage_energy_monitoring_result.pyi | 18 +++ .../tapo/responses/device_usage_result.pyi | 22 ++++ .../tapo/responses/energy_data_result.pyi | 27 ++++ .../tapo/responses/energy_usage_result.pyi | 24 ++++ tapo-py/tapo-py/tapo/types.pyi | 108 ---------------- 33 files changed, 587 insertions(+), 509 deletions(-) create mode 100644 tapo-py/tapo-py/tapo/requests/__init__.py create mode 100644 tapo-py/tapo-py/tapo/requests/__init__.pyi create mode 100644 tapo-py/tapo-py/tapo/requests/color.pyi create mode 100644 tapo-py/tapo-py/tapo/requests/energy_data_interval.pyi create mode 100644 tapo-py/tapo-py/tapo/requests/set_device_info/__init__.py create mode 100644 tapo-py/tapo-py/tapo/requests/set_device_info/__init__.pyi create mode 100644 tapo-py/tapo-py/tapo/requests/set_device_info/color_light.pyi create mode 100644 tapo-py/tapo-py/tapo/responses/current_power_result.pyi create mode 100644 tapo-py/tapo-py/tapo/responses/default_state.pyi create mode 100644 tapo-py/tapo-py/tapo/responses/device_info_result/__init__.py create mode 100644 tapo-py/tapo-py/tapo/responses/device_info_result/__init__.pyi create mode 100644 tapo-py/tapo-py/tapo/responses/device_info_result/color_light_result.pyi create mode 100644 tapo-py/tapo-py/tapo/responses/device_info_result/generic_result.pyi create mode 100644 tapo-py/tapo-py/tapo/responses/device_info_result/hub_result.pyi create mode 100644 tapo-py/tapo-py/tapo/responses/device_info_result/light_result.pyi create mode 100644 tapo-py/tapo-py/tapo/responses/device_info_result/plug_result.pyi create mode 100644 tapo-py/tapo-py/tapo/responses/device_usage_energy_monitoring_result.pyi create mode 100644 tapo-py/tapo-py/tapo/responses/device_usage_result.pyi create mode 100644 tapo-py/tapo-py/tapo/responses/energy_data_result.pyi create mode 100644 tapo-py/tapo-py/tapo/responses/energy_usage_result.pyi delete mode 100644 tapo-py/tapo-py/tapo/types.pyi diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b4dab1..42ac91e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,10 @@ file. This change log follows the conventions of - Added partial support for the H100 hub and it's child devices. Currently, only the `get_device_info` function is supported for the child devices through the hub's `get_child_device_list` method. +### Changed + +- A large number of types have been reorganized to me more in line with the Rust library. This includes moving many of them under the `requests` and `responses` sub modules. + ### Removed - `l900` has been removed from the `ApiClient` until proper support is added. diff --git a/tapo-py/examples/tapo_l530.py b/tapo-py/examples/tapo_l530.py index 0c16d12..ddcaf6f 100644 --- a/tapo-py/examples/tapo_l530.py +++ b/tapo-py/examples/tapo_l530.py @@ -3,7 +3,8 @@ import asyncio import os -from tapo import ApiClient, Color +from tapo import ApiClient +from tapo.requests import Color async def main(): diff --git a/tapo-py/examples/tapo_p110.py b/tapo-py/examples/tapo_p110.py index 8df0d59..62816ca 100644 --- a/tapo-py/examples/tapo_p110.py +++ b/tapo-py/examples/tapo_p110.py @@ -4,7 +4,8 @@ import os from datetime import datetime -from tapo import ApiClient, EnergyDataInterval +from tapo import ApiClient +from tapo.requests import EnergyDataInterval async def main(): diff --git a/tapo-py/src/lib.rs b/tapo-py/src/lib.rs index aca4ee9..042c297 100644 --- a/tapo-py/src/lib.rs +++ b/tapo-py/src/lib.rs @@ -5,11 +5,16 @@ mod handlers; use pyo3::prelude::*; use api_client::PyApiClient; -use handlers::PyEnergyDataInterval; +use handlers::{PyColorLightSetDeviceInfoParams, PyEnergyDataInterval}; use tapo::requests::Color; use tapo::responses::{ - KE100Result, S200BResult, Status, T100Result, T110Result, T300Result, T31XResult, - TemperatureUnit, TemperatureUnitKE100, WaterLeakStatus, + ColorLightState, CurrentPowerResult, DefaultBrightnessState, DefaultColorLightState, + DefaultLightState, DefaultPlugState, DefaultPowerType, DefaultStateType, + DeviceInfoColorLightResult, DeviceInfoGenericResult, DeviceInfoHubResult, + DeviceInfoLightResult, DeviceInfoPlugResult, DeviceUsageEnergyMonitoringResult, + DeviceUsageResult, EnergyDataResult, EnergyUsageResult, KE100Result, PlugState, S200BResult, + Status, T100Result, T110Result, T300Result, T31XResult, TemperatureUnit, TemperatureUnitKE100, + UsageByPeriodResult, WaterLeakStatus, }; #[pymodule] @@ -17,16 +22,35 @@ use tapo::responses::{ fn tapo_py(py: Python, module: &PyModule) -> PyResult<()> { module.add_class::()?; - module.add_class::()?; - module.add_class::()?; - + let requests = PyModule::new(py, "tapo.requests")?; let responses = PyModule::new(py, "tapo.responses")?; - responses.add_class::()?; - responses.add_class::()?; - responses.add_class::()?; - responses.add_class::()?; + // requests + requests.add_class::()?; + requests.add_class::()?; + requests.add_class::()?; + + // responses + responses.add_class::()?; + responses.add_class::()?; + responses.add_class::()?; + responses.add_class::()?; + responses.add_class::()?; + responses.add_class::()?; + responses.add_class::()?; + responses.add_class::()?; + responses.add_class::()?; + + // responses: device info: color light + responses.add_class::()?; + responses.add_class::()?; + responses.add_class::()?; + + // responses: device info: generic + responses.add_class::()?; + // responses: hub + responses.add_class::()?; responses.add_class::()?; responses.add_class::()?; responses.add_class::()?; @@ -34,10 +58,27 @@ fn tapo_py(py: Python, module: &PyModule) -> PyResult<()> { responses.add_class::()?; responses.add_class::()?; + // responses: hub devices + responses.add_class::()?; + responses.add_class::()?; + responses.add_class::()?; + responses.add_class::()?; + + // responses: light + responses.add_class::()?; + responses.add_class::()?; + + // responses: plug + responses.add_class::()?; + responses.add_class::()?; + responses.add_class::()?; + let sys = py.import("sys")?; let modules = sys.getattr("modules")?; + modules.set_item("tapo.requests", requests)?; modules.set_item("tapo.responses", responses)?; + module.add_submodule(requests)?; module.add_submodule(responses)?; Ok(()) diff --git a/tapo-py/tapo-py/tapo/__init__.pyi b/tapo-py/tapo-py/tapo/__init__.pyi index fd38af7..03e7cea 100644 --- a/tapo-py/tapo-py/tapo/__init__.pyi +++ b/tapo-py/tapo-py/tapo/__init__.pyi @@ -5,5 +5,5 @@ from .hub_handler import * from .light_handler import * from .plug_energy_monitoring_handler import * from .plug_handler import * +from .requests import * from .responses import * -from .types import * diff --git a/tapo-py/tapo-py/tapo/color_light_handler.pyi b/tapo-py/tapo-py/tapo/color_light_handler.pyi index d4a1bac..cdb5862 100644 --- a/tapo-py/tapo-py/tapo/color_light_handler.pyi +++ b/tapo-py/tapo-py/tapo/color_light_handler.pyi @@ -1,6 +1,5 @@ -from typing import Optional - -from .types import Color, DefaultStateType, DefaultStateType, DeviceUsageResult +from tapo.responses import DeviceInfoColorLightResult, DeviceUsageResult +from tapo.requests import Color, ColorLightSetDeviceInfoParams class ColorLightHandler: """Handler for the [L530](https://www.tapo.com/en/search/?q=L530) and [L630](https://www.tapo.com/en/search/?q=L630) devices.""" @@ -95,120 +94,3 @@ class ColorLightHandler: Args: color_temperature (int): between 2500 and 6500 """ - -class DeviceInfoColorLightResult: - """Device info of Tapo L530, L630 and L900. Superset of `GenericDeviceInfoResult`.""" - - device_id: str - type: str - model: str - hw_id: str - hw_ver: str - fw_id: str - fw_ver: str - oem_id: str - mac: str - ip: str - ssid: str - signal_level: int - rssi: int - specs: str - lang: str - device_on: bool - on_time: int - """The time in seconds this device has been ON since the last state change (ON/OFF).""" - overheated: bool - nickname: str - avatar: str - has_set_location_info: bool - region: Optional[str] - latitude: Optional[float] - longitude: Optional[float] - time_diff: Optional[int] - - # Unique to this device - brightness: int - dynamic_light_effect_enable: bool - dynamic_light_effect_id: Optional[str] - hue: Optional[int] - saturation: Optional[int] - color_temp: int - default_states: DefaultColorLightState - """The default state of a device to be used when internet connectivity is lost after a power cut.""" - - def to_dict(self) -> dict: - """Gets all the properties of this result as a dictionary. - - Returns: - dict: The result as a dictionary. - """ - -class DefaultColorLightState: - """Color Light Default State.""" - - type: DefaultStateType - state: ColorLightState - -class ColorLightState: - """Color Light State.""" - - brightness: int - hue: Optional[int] - saturation: Optional[int] - color_temp: int - -class ColorLightSetDeviceInfoParams: - """Builder that is used by the `ColorLightHandler.set` API to set - multiple properties in a single request. - """ - - def on(self) -> ColorLightSetDeviceInfoParams: - """Turns *on* the device. - `ColorLightSetDeviceInfoParams.send` must be called at the end to apply the changes. - """ - - def off(self) -> ColorLightSetDeviceInfoParams: - """Turns *off* the device. - `ColorLightSetDeviceInfoParams.send` must be called at the end to apply the changes. - """ - - def brightness(self, brightness: int) -> ColorLightSetDeviceInfoParams: - """Sets the *brightness*. - `ColorLightSetDeviceInfoParams.send` must be called at the end to apply the changes. - The device will also be turned *on*, unless `ColorLightSetDeviceInfoParams.off` is called. - - Args: - brightness (int): between 1 and 100 - """ - - def color(self, color: Color) -> ColorLightSetDeviceInfoParams: - """Sets the *color*. - `ColorLightSetDeviceInfoParams.send` must be called at the end to apply the changes. - The device will also be turned *on*, unless `ColorLightSetDeviceInfoParams.off` is called. - - Args: - color (Color): one of `tapo.Color` as defined in the Google Home app. - """ - - def hue_saturation(self, hue: int, saturation: int) -> ColorLightSetDeviceInfoParams: - """Sets the *hue* and *saturation*. - `ColorLightSetDeviceInfoParams.send` must be called at the end to apply the changes. - The device will also be turned *on*, unless `ColorLightSetDeviceInfoParams.off` is called. - - Args: - hue (int): between 1 and 360 - saturation (int): between 1 and 100 - """ - - def color_temperature(self, color_temperature: int) -> ColorLightSetDeviceInfoParams: - """ - Sets the *color temperature*. - `ColorLightSetDeviceInfoParams.send` must be called at the end to apply the changes. - The device will also be turned *on*, unless `ColorLightSetDeviceInfoParams.off` is called. - - Args: - color_temperature (int): between 2500 and 6500 - """ - - async def send(self) -> None: - """Performs a request to apply the changes to the device.""" diff --git a/tapo-py/tapo-py/tapo/generic_device_handler.pyi b/tapo-py/tapo-py/tapo/generic_device_handler.pyi index b8f24b6..8262107 100644 --- a/tapo-py/tapo-py/tapo/generic_device_handler.pyi +++ b/tapo-py/tapo-py/tapo/generic_device_handler.pyi @@ -1,4 +1,4 @@ -from typing import Optional +from tapo.responses import DeviceInfoGenericResult class GenericDeviceHandler: """Handler for generic devices. It provides the functionality common to @@ -36,40 +36,3 @@ class GenericDeviceHandler: Returns: dict: Device info as a dictionary. """ - -class DeviceInfoGenericResult: - """Device info of a Generic Tapo device.""" - - device_id: str - type: str - model: str - hw_id: str - hw_ver: str - fw_id: str - fw_ver: str - oem_id: str - mac: str - ip: str - ssid: str - signal_level: int - rssi: int - specs: str - lang: str - device_on: Optional[bool] - on_time: Optional[int] - """The time in seconds this device has been ON since the last state change (ON/OFF).""" - overheated: bool - nickname: str - avatar: str - has_set_location_info: bool - region: Optional[str] - latitude: Optional[float] - longitude: Optional[float] - time_diff: Optional[int] - - def to_dict(self) -> dict: - """Gets all the properties of this result as a dictionary. - - Returns: - dict: The result as a dictionary. - """ diff --git a/tapo-py/tapo-py/tapo/hub_handler.pyi b/tapo-py/tapo-py/tapo/hub_handler.pyi index 045304f..8d4c11f 100644 --- a/tapo-py/tapo-py/tapo/hub_handler.pyi +++ b/tapo-py/tapo-py/tapo/hub_handler.pyi @@ -1,6 +1,14 @@ -from typing import List, Optional, Union - -from tapo.responses import KE100Result, S200BResult, T100Result, T110Result, T300Result, T31XResult +from typing import List, Union + +from tapo.responses import ( + DeviceInfoHubResult, + KE100Result, + S200BResult, + T100Result, + T110Result, + T300Result, + T31XResult, +) class HubHandler: """Handler for the [H100](https://www.tapo.com/en/search/?q=H100) hubs.""" @@ -62,41 +70,3 @@ class HubHandler: Returns: dict: Device info as a dictionary. """ - -class DeviceInfoHubResult: - """Device info of Tapo H100. Superset of `GenericDeviceInfoResult`.""" - - device_id: str - type: str - model: str - hw_id: str - hw_ver: str - fw_id: str - fw_ver: str - oem_id: str - mac: str - ip: str - ssid: str - signal_level: int - rssi: int - specs: str - lang: str - overheated: bool - nickname: str - avatar: str - has_set_location_info: bool - region: Optional[str] - latitude: Optional[float] - longitude: Optional[float] - time_diff: Optional[int] - - # Unique to this device - in_alarm: bool - in_alarm_source: str - - def to_dict(self) -> dict: - """Gets all the properties of this result as a dictionary. - - Returns: - dict: The result as a dictionary. - """ diff --git a/tapo-py/tapo-py/tapo/light_handler.pyi b/tapo-py/tapo-py/tapo/light_handler.pyi index 2ed692a..1426e52 100644 --- a/tapo-py/tapo-py/tapo/light_handler.pyi +++ b/tapo-py/tapo-py/tapo/light_handler.pyi @@ -1,11 +1,4 @@ -from enum import StrEnum -from typing import Optional - -from .types import ( - DefaultBrightnessState, - DefaultPowerType, - DeviceUsageResult, -) +from tapo.responses import DeviceInfoLightResult, DeviceUsageResult class LightHandler: """Handler for the [L510](https://www.tapo.com/en/search/?q=L510), [L520](https://www.tapo.com/en/search/?q=L520) and [L610](https://www.tapo.com/en/search/?q=L610) devices.""" @@ -68,51 +61,3 @@ class LightHandler: Args: brightness (int): between 1 and 100 """ - -class DeviceInfoLightResult: - """Device info of Tapo L510, L520 and L610. Superset of `GenericDeviceInfoResult`.""" - - device_id: str - type: str - model: str - hw_id: str - hw_ver: str - fw_id: str - fw_ver: str - oem_id: str - mac: str - ip: str - ssid: str - signal_level: int - rssi: int - specs: str - lang: str - device_on: bool - on_time: int - """The time in seconds this device has been ON since the last state change (ON/OFF).""" - overheated: bool - nickname: str - avatar: str - has_set_location_info: bool - region: Optional[str] - latitude: Optional[float] - longitude: Optional[float] - time_diff: Optional[int] - - # Unique to this device - brightness: int - default_states: DefaultLightState - """The default state of a device to be used when internet connectivity is lost after a power cut.""" - - def to_dict(self) -> dict: - """Gets all the properties of this result as a dictionary. - - Returns: - dict: The result as a dictionary. - """ - -class DefaultLightState: - """Light Default State.""" - - brightness: DefaultBrightnessState - re_power_type: Optional[DefaultPowerType] diff --git a/tapo-py/tapo-py/tapo/plug_energy_monitoring_handler.pyi b/tapo-py/tapo-py/tapo/plug_energy_monitoring_handler.pyi index 03ca2ac..53fd755 100644 --- a/tapo-py/tapo-py/tapo/plug_energy_monitoring_handler.pyi +++ b/tapo-py/tapo-py/tapo/plug_energy_monitoring_handler.pyi @@ -1,9 +1,13 @@ from datetime import datetime -from enum import StrEnum -from typing import List -from .types import DeviceUsageEnergyMonitoringResult -from .plug_handler import DeviceInfoPlugResult +from tapo.requests import EnergyDataInterval +from tapo.responses import ( + CurrentPowerResult, + DeviceInfoPlugResult, + DeviceUsageEnergyMonitoringResult, + EnergyDataResult, + EnergyUsageResult, +) class PlugEnergyMonitoringHandler: """Handler for the [P110](https://www.tapo.com/en/search/?q=P110) & [P115](https://www.tapo.com/en/search/?q=P115) devices.""" @@ -87,78 +91,3 @@ class PlugEnergyMonitoringHandler: Returns: EnergyDataResult: Energy data for the requested `EnergyDataInterval`. """ - -class CurrentPowerResult: - """Contains the current power reading of the device.""" - - current_power: int - """Current power in watts (W).""" - - def to_dict(self) -> dict: - """Gets all the properties of this result as a dictionary. - - Returns: - dict: The result as a dictionary. - """ - -class EnergyUsageResult: - """Contains local time, current power and the energy usage and runtime for today and for the current month.""" - - local_time: datetime - """Local time of the device.""" - current_power: int - """Current power in milliwatts (mW).""" - today_runtime: int - """Today runtime in minutes.""" - today_energy: int - """Today energy usage in watts (W).""" - month_runtime: int - """Current month runtime in minutes.""" - month_energy: int - """Current month energy usage in watts (W).""" - - def to_dict(self) -> dict: - """Gets all the properties of this result as a dictionary. - - Returns: - dict: The result as a dictionary. - """ - -class EnergyDataResult: - """Energy data for the requested `EnergyDataInterval`.""" - - local_time: datetime - """Local time of the device.""" - - data: List[int] - """Energy data for the given `interval` in watts (W).""" - - start_timestamp: int - """Interval start timestamp in milliseconds.""" - - end_timestamp: int - """Interval end timestamp in milliseconds.""" - - interval: int - """Interval in minutes.""" - - def to_dict(self) -> dict: - """Gets all the properties of this result as a dictionary. - - Returns: - dict: The result as a dictionary. - """ - -class EnergyDataInterval(StrEnum): - """Energy data interval.""" - - Hourly = "Hourly" - """Hourly interval. `start_date` and `end_date` are an inclusive interval - that must not be greater than 8 days. - """ - - Daily = "Daily" - """Daily interval. `start_date` must be the first day of a quarter.""" - - Monthly = "Monthly" - """Monthly interval. `start_date` must be the first day of a year.""" diff --git a/tapo-py/tapo-py/tapo/plug_handler.pyi b/tapo-py/tapo-py/tapo/plug_handler.pyi index 87440a4..153f237 100644 --- a/tapo-py/tapo-py/tapo/plug_handler.pyi +++ b/tapo-py/tapo-py/tapo/plug_handler.pyi @@ -1,5 +1,4 @@ -from typing import Optional -from .types import DefaultStateType, DeviceUsageResult +from tapo.responses import DeviceInfoPlugResult, DeviceUsageResult class PlugHandler: """Handler for the [P100](https://www.tapo.com/en/search/?q=P100) & [P105](https://www.tapo.com/en/search/?q=P105) devices.""" @@ -55,55 +54,3 @@ class PlugHandler: Returns: DeviceUsageResult: Contains the time usage. """ - -class DeviceInfoPlugResult: - """Device info of Tapo P100, P105, P110 and P115. Superset of `GenericDeviceInfoResult`.""" - - device_id: str - type: str - model: str - hw_id: str - hw_ver: str - fw_id: str - fw_ver: str - oem_id: str - mac: str - ip: str - ssid: str - signal_level: int - rssi: int - specs: str - lang: str - device_on: bool - on_time: int - """The time in seconds this device has been ON since the last state change (ON/OFF).""" - overheated: bool - nickname: str - avatar: str - has_set_location_info: bool - region: Optional[str] - latitude: Optional[float] - longitude: Optional[float] - time_diff: Optional[int] - - # Unique to this device - default_states: PlugDefaultState - """The default state of a device to be used when internet connectivity is lost after a power cut.""" - - def to_dict(self) -> dict: - """Gets all the properties of this result as a dictionary. - - Returns: - dict: The result as a dictionary. - """ - -class PlugDefaultState: - """Plug Default State.""" - - type: DefaultStateType - state: PlugState - -class PlugState: - """Plug State.""" - - on: Optional[bool] diff --git a/tapo-py/tapo-py/tapo/requests/__init__.py b/tapo-py/tapo-py/tapo/requests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tapo-py/tapo-py/tapo/requests/__init__.pyi b/tapo-py/tapo-py/tapo/requests/__init__.pyi new file mode 100644 index 0000000..db49f83 --- /dev/null +++ b/tapo-py/tapo-py/tapo/requests/__init__.pyi @@ -0,0 +1,3 @@ +from .color import * +from .energy_data_interval import * +from .set_device_info import * diff --git a/tapo-py/tapo-py/tapo/requests/color.pyi b/tapo-py/tapo-py/tapo/requests/color.pyi new file mode 100644 index 0000000..04bdf1d --- /dev/null +++ b/tapo-py/tapo-py/tapo/requests/color.pyi @@ -0,0 +1,46 @@ +from enum import Enum + +class Color(str, Enum): + """List of preset colors as defined in the Google Home app.""" + + CoolWhite = "CoolWhite" + Daylight = "Daylight" + Ivory = "Ivory" + WarmWhite = "WarmWhite" + Incandescent = "Incandescent" + Candlelight = "Candlelight" + Snow = "Snow" + GhostWhite = "GhostWhite" + AliceBlue = "AliceBlue" + LightGoldenrod = "LightGoldenrod" + LemonChiffon = "LemonChiffon" + AntiqueWhite = "AntiqueWhite" + Gold = "Gold" + Peru = "Peru" + Chocolate = "Chocolate" + SandyBrown = "SandyBrown" + Coral = "Coral" + Pumpkin = "Pumpkin" + Tomato = "Tomato" + Vermilion = "Vermilion" + OrangeRed = "OrangeRed" + Pink = "Pink" + Crimson = "Crimson" + DarkRed = "DarkRed" + HotPink = "HotPink" + Smitten = "Smitten" + MediumPurple = "MediumPurple" + BlueViolet = "BlueViolet" + Indigo = "Indigo" + LightSkyBlue = "LightSkyBlue" + CornflowerBlue = "CornflowerBlue" + Ultramarine = "Ultramarine" + DeepSkyBlue = "DeepSkyBlue" + Azure = "Azure" + NavyBlue = "NavyBlue" + LightTurquoise = "LightTurquoise" + Aquamarine = "Aquamarine" + Turquoise = "Turquoise" + LightGreen = "LightGreen" + Lime = "Lime" + ForestGreen = "ForestGreen" diff --git a/tapo-py/tapo-py/tapo/requests/energy_data_interval.pyi b/tapo-py/tapo-py/tapo/requests/energy_data_interval.pyi new file mode 100644 index 0000000..38a3cfc --- /dev/null +++ b/tapo-py/tapo-py/tapo/requests/energy_data_interval.pyi @@ -0,0 +1,15 @@ +from enum import Enum + +class EnergyDataInterval(str, Enum): + """Energy data interval.""" + + Hourly = "Hourly" + """Hourly interval. `start_date` and `end_date` are an inclusive interval + that must not be greater than 8 days. + """ + + Daily = "Daily" + """Daily interval. `start_date` must be the first day of a quarter.""" + + Monthly = "Monthly" + """Monthly interval. `start_date` must be the first day of a year.""" diff --git a/tapo-py/tapo-py/tapo/requests/set_device_info/__init__.py b/tapo-py/tapo-py/tapo/requests/set_device_info/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tapo-py/tapo-py/tapo/requests/set_device_info/__init__.pyi b/tapo-py/tapo-py/tapo/requests/set_device_info/__init__.pyi new file mode 100644 index 0000000..62b5eaf --- /dev/null +++ b/tapo-py/tapo-py/tapo/requests/set_device_info/__init__.pyi @@ -0,0 +1 @@ +from .color_light import * diff --git a/tapo-py/tapo-py/tapo/requests/set_device_info/color_light.pyi b/tapo-py/tapo-py/tapo/requests/set_device_info/color_light.pyi new file mode 100644 index 0000000..31da309 --- /dev/null +++ b/tapo-py/tapo-py/tapo/requests/set_device_info/color_light.pyi @@ -0,0 +1,57 @@ +from tapo.requests import Color + +class ColorLightSetDeviceInfoParams: + """Builder that is used by the `ColorLightHandler.set` API to set + multiple properties in a single request. + """ + + def on(self) -> ColorLightSetDeviceInfoParams: + """Turns *on* the device. + `ColorLightSetDeviceInfoParams.send` must be called at the end to apply the changes. + """ + + def off(self) -> ColorLightSetDeviceInfoParams: + """Turns *off* the device. + `ColorLightSetDeviceInfoParams.send` must be called at the end to apply the changes. + """ + + def brightness(self, brightness: int) -> ColorLightSetDeviceInfoParams: + """Sets the *brightness*. + `ColorLightSetDeviceInfoParams.send` must be called at the end to apply the changes. + The device will also be turned *on*, unless `ColorLightSetDeviceInfoParams.off` is called. + + Args: + brightness (int): between 1 and 100 + """ + + def color(self, color: Color) -> ColorLightSetDeviceInfoParams: + """Sets the *color*. + `ColorLightSetDeviceInfoParams.send` must be called at the end to apply the changes. + The device will also be turned *on*, unless `ColorLightSetDeviceInfoParams.off` is called. + + Args: + color (Color): one of `tapo.Color` as defined in the Google Home app. + """ + + def hue_saturation(self, hue: int, saturation: int) -> ColorLightSetDeviceInfoParams: + """Sets the *hue* and *saturation*. + `ColorLightSetDeviceInfoParams.send` must be called at the end to apply the changes. + The device will also be turned *on*, unless `ColorLightSetDeviceInfoParams.off` is called. + + Args: + hue (int): between 1 and 360 + saturation (int): between 1 and 100 + """ + + def color_temperature(self, color_temperature: int) -> ColorLightSetDeviceInfoParams: + """ + Sets the *color temperature*. + `ColorLightSetDeviceInfoParams.send` must be called at the end to apply the changes. + The device will also be turned *on*, unless `ColorLightSetDeviceInfoParams.off` is called. + + Args: + color_temperature (int): between 2500 and 6500 + """ + + async def send(self) -> None: + """Performs a request to apply the changes to the device.""" diff --git a/tapo-py/tapo-py/tapo/responses/__init__.pyi b/tapo-py/tapo-py/tapo/responses/__init__.pyi index 6671ef3..711b4ce 100644 --- a/tapo-py/tapo-py/tapo/responses/__init__.pyi +++ b/tapo-py/tapo-py/tapo/responses/__init__.pyi @@ -1 +1,8 @@ from .child_device_hub_result import * +from .current_power_result import * +from .default_state import * +from .device_info_result import * +from .device_usage_energy_monitoring_result import * +from .device_usage_result import * +from .energy_data_result import * +from .energy_usage_result import * diff --git a/tapo-py/tapo-py/tapo/responses/current_power_result.pyi b/tapo-py/tapo-py/tapo/responses/current_power_result.pyi new file mode 100644 index 0000000..7a69514 --- /dev/null +++ b/tapo-py/tapo-py/tapo/responses/current_power_result.pyi @@ -0,0 +1,12 @@ +class CurrentPowerResult: + """Contains the current power reading of the device.""" + + current_power: int + """Current power in watts (W).""" + + def to_dict(self) -> dict: + """Gets all the properties of this result as a dictionary. + + Returns: + dict: The result as a dictionary. + """ diff --git a/tapo-py/tapo-py/tapo/responses/default_state.pyi b/tapo-py/tapo-py/tapo/responses/default_state.pyi new file mode 100644 index 0000000..d9c40b1 --- /dev/null +++ b/tapo-py/tapo-py/tapo/responses/default_state.pyi @@ -0,0 +1,19 @@ +from enum import Enum + +class DefaultBrightnessState: + """Default brightness state.""" + + type: DefaultStateType + value: int + +class DefaultStateType(str, Enum): + """The type of the default state.""" + + Custom = "custom" + LastStates = "last_states" + +class DefaultPowerType(str, Enum): + """The type of the default power state.""" + + AlwaysOn = "always_on" + LastStates = "last_states" diff --git a/tapo-py/tapo-py/tapo/responses/device_info_result/__init__.py b/tapo-py/tapo-py/tapo/responses/device_info_result/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tapo-py/tapo-py/tapo/responses/device_info_result/__init__.pyi b/tapo-py/tapo-py/tapo/responses/device_info_result/__init__.pyi new file mode 100644 index 0000000..fe4c9fd --- /dev/null +++ b/tapo-py/tapo-py/tapo/responses/device_info_result/__init__.pyi @@ -0,0 +1,5 @@ +from .color_light_result import * +from .generic_result import * +from .hub_result import * +from .light_result import * +from .plug_result import * diff --git a/tapo-py/tapo-py/tapo/responses/device_info_result/color_light_result.pyi b/tapo-py/tapo-py/tapo/responses/device_info_result/color_light_result.pyi new file mode 100644 index 0000000..4954d74 --- /dev/null +++ b/tapo-py/tapo-py/tapo/responses/device_info_result/color_light_result.pyi @@ -0,0 +1,64 @@ +from typing import Optional + +from tapo.responses.default_state import DefaultStateType + +class DeviceInfoColorLightResult: + """Device info of Tapo L530, L630 and L900. Superset of `GenericDeviceInfoResult`.""" + + device_id: str + type: str + model: str + hw_id: str + hw_ver: str + fw_id: str + fw_ver: str + oem_id: str + mac: str + ip: str + ssid: str + signal_level: int + rssi: int + specs: str + lang: str + device_on: bool + on_time: int + """The time in seconds this device has been ON since the last state change (ON/OFF).""" + overheated: bool + nickname: str + avatar: str + has_set_location_info: bool + region: Optional[str] + latitude: Optional[float] + longitude: Optional[float] + time_diff: Optional[int] + + # Unique to this device + brightness: int + dynamic_light_effect_enable: bool + dynamic_light_effect_id: Optional[str] + hue: Optional[int] + saturation: Optional[int] + color_temp: int + default_states: DefaultColorLightState + """The default state of a device to be used when internet connectivity is lost after a power cut.""" + + def to_dict(self) -> dict: + """Gets all the properties of this result as a dictionary. + + Returns: + dict: The result as a dictionary. + """ + +class DefaultColorLightState: + """Color Light Default State.""" + + type: DefaultStateType + state: ColorLightState + +class ColorLightState: + """Color Light State.""" + + brightness: int + hue: Optional[int] + saturation: Optional[int] + color_temp: int diff --git a/tapo-py/tapo-py/tapo/responses/device_info_result/generic_result.pyi b/tapo-py/tapo-py/tapo/responses/device_info_result/generic_result.pyi new file mode 100644 index 0000000..6fe19f3 --- /dev/null +++ b/tapo-py/tapo-py/tapo/responses/device_info_result/generic_result.pyi @@ -0,0 +1,38 @@ +from typing import Optional + +class DeviceInfoGenericResult: + """Device info of a Generic Tapo device.""" + + device_id: str + type: str + model: str + hw_id: str + hw_ver: str + fw_id: str + fw_ver: str + oem_id: str + mac: str + ip: str + ssid: str + signal_level: int + rssi: int + specs: str + lang: str + device_on: Optional[bool] + on_time: Optional[int] + """The time in seconds this device has been ON since the last state change (ON/OFF).""" + overheated: bool + nickname: str + avatar: str + has_set_location_info: bool + region: Optional[str] + latitude: Optional[float] + longitude: Optional[float] + time_diff: Optional[int] + + def to_dict(self) -> dict: + """Gets all the properties of this result as a dictionary. + + Returns: + dict: The result as a dictionary. + """ diff --git a/tapo-py/tapo-py/tapo/responses/device_info_result/hub_result.pyi b/tapo-py/tapo-py/tapo/responses/device_info_result/hub_result.pyi new file mode 100644 index 0000000..f992fa5 --- /dev/null +++ b/tapo-py/tapo-py/tapo/responses/device_info_result/hub_result.pyi @@ -0,0 +1,39 @@ +from typing import Optional + +class DeviceInfoHubResult: + """Device info of Tapo H100. Superset of `GenericDeviceInfoResult`.""" + + device_id: str + type: str + model: str + hw_id: str + hw_ver: str + fw_id: str + fw_ver: str + oem_id: str + mac: str + ip: str + ssid: str + signal_level: int + rssi: int + specs: str + lang: str + overheated: bool + nickname: str + avatar: str + has_set_location_info: bool + region: Optional[str] + latitude: Optional[float] + longitude: Optional[float] + time_diff: Optional[int] + + # Unique to this device + in_alarm: bool + in_alarm_source: str + + def to_dict(self) -> dict: + """Gets all the properties of this result as a dictionary. + + Returns: + dict: The result as a dictionary. + """ diff --git a/tapo-py/tapo-py/tapo/responses/device_info_result/light_result.pyi b/tapo-py/tapo-py/tapo/responses/device_info_result/light_result.pyi new file mode 100644 index 0000000..e1114e9 --- /dev/null +++ b/tapo-py/tapo-py/tapo/responses/device_info_result/light_result.pyi @@ -0,0 +1,51 @@ +from typing import Optional + +from tapo.responses import DefaultBrightnessState, DefaultPowerType + +class DeviceInfoLightResult: + """Device info of Tapo L510, L520 and L610. Superset of `GenericDeviceInfoResult`.""" + + device_id: str + type: str + model: str + hw_id: str + hw_ver: str + fw_id: str + fw_ver: str + oem_id: str + mac: str + ip: str + ssid: str + signal_level: int + rssi: int + specs: str + lang: str + device_on: bool + on_time: int + """The time in seconds this device has been ON since the last state change (ON/OFF).""" + overheated: bool + nickname: str + avatar: str + has_set_location_info: bool + region: Optional[str] + latitude: Optional[float] + longitude: Optional[float] + time_diff: Optional[int] + + # Unique to this device + brightness: int + default_states: DefaultLightState + """The default state of a device to be used when internet connectivity is lost after a power cut.""" + + def to_dict(self) -> dict: + """Gets all the properties of this result as a dictionary. + + Returns: + dict: The result as a dictionary. + """ + +class DefaultLightState: + """Light Default State.""" + + brightness: DefaultBrightnessState + re_power_type: Optional[DefaultPowerType] diff --git a/tapo-py/tapo-py/tapo/responses/device_info_result/plug_result.pyi b/tapo-py/tapo-py/tapo/responses/device_info_result/plug_result.pyi new file mode 100644 index 0000000..e3e95ca --- /dev/null +++ b/tapo-py/tapo-py/tapo/responses/device_info_result/plug_result.pyi @@ -0,0 +1,55 @@ +from typing import Optional + +from tapo.responses import DefaultStateType + +class DeviceInfoPlugResult: + """Device info of Tapo P100, P105, P110 and P115. Superset of `GenericDeviceInfoResult`.""" + + device_id: str + type: str + model: str + hw_id: str + hw_ver: str + fw_id: str + fw_ver: str + oem_id: str + mac: str + ip: str + ssid: str + signal_level: int + rssi: int + specs: str + lang: str + device_on: bool + on_time: int + """The time in seconds this device has been ON since the last state change (ON/OFF).""" + overheated: bool + nickname: str + avatar: str + has_set_location_info: bool + region: Optional[str] + latitude: Optional[float] + longitude: Optional[float] + time_diff: Optional[int] + + # Unique to this device + default_states: DefaultPlugState + """The default state of a device to be used when internet connectivity is lost after a power cut.""" + + def to_dict(self) -> dict: + """Gets all the properties of this result as a dictionary. + + Returns: + dict: The result as a dictionary. + """ + +class DefaultPlugState: + """Default Plug State.""" + + type: DefaultStateType + state: PlugState + +class PlugState: + """Plug State.""" + + on: Optional[bool] diff --git a/tapo-py/tapo-py/tapo/responses/device_usage_energy_monitoring_result.pyi b/tapo-py/tapo-py/tapo/responses/device_usage_energy_monitoring_result.pyi new file mode 100644 index 0000000..e488fdd --- /dev/null +++ b/tapo-py/tapo-py/tapo/responses/device_usage_energy_monitoring_result.pyi @@ -0,0 +1,18 @@ +from tapo.responses import UsageByPeriodResult + +class DeviceUsageEnergyMonitoringResult: + """Contains the time usage, the power consumption, and the energy savings of the device.""" + + time_usage: UsageByPeriodResult + """Time usage in minutes.""" + power_usage: UsageByPeriodResult + """Power usage in watt-hour (Wh).""" + saved_power: UsageByPeriodResult + """Saved power in watt-hour (Wh).""" + + def to_dict(self) -> dict: + """Gets all the properties of this result as a dictionary. + + Returns: + dict: The result as a dictionary. + """ diff --git a/tapo-py/tapo-py/tapo/responses/device_usage_result.pyi b/tapo-py/tapo-py/tapo/responses/device_usage_result.pyi new file mode 100644 index 0000000..fc942ce --- /dev/null +++ b/tapo-py/tapo-py/tapo/responses/device_usage_result.pyi @@ -0,0 +1,22 @@ +class UsageByPeriodResult: + """Usage by period result for today, the past 7 days, and the past 30 days.""" + + today: int + """Today.""" + past7: int + """Past 7 days.""" + past30: int + """Past 30 days.""" + +class DeviceUsageResult: + """Contains the time usage.""" + + time_usage: UsageByPeriodResult + """Time usage in minutes.""" + + def to_dict(self) -> dict: + """Gets all the properties of this result as a dictionary. + + Returns: + dict: The result as a dictionary. + """ diff --git a/tapo-py/tapo-py/tapo/responses/energy_data_result.pyi b/tapo-py/tapo-py/tapo/responses/energy_data_result.pyi new file mode 100644 index 0000000..d689a39 --- /dev/null +++ b/tapo-py/tapo-py/tapo/responses/energy_data_result.pyi @@ -0,0 +1,27 @@ +from datetime import datetime +from typing import List + +class EnergyDataResult: + """Energy data for the requested `EnergyDataInterval`.""" + + local_time: datetime + """Local time of the device.""" + + data: List[int] + """Energy data for the given `interval` in watts (W).""" + + start_timestamp: int + """Interval start timestamp in milliseconds.""" + + end_timestamp: int + """Interval end timestamp in milliseconds.""" + + interval: int + """Interval in minutes.""" + + def to_dict(self) -> dict: + """Gets all the properties of this result as a dictionary. + + Returns: + dict: The result as a dictionary. + """ diff --git a/tapo-py/tapo-py/tapo/responses/energy_usage_result.pyi b/tapo-py/tapo-py/tapo/responses/energy_usage_result.pyi new file mode 100644 index 0000000..90e73fd --- /dev/null +++ b/tapo-py/tapo-py/tapo/responses/energy_usage_result.pyi @@ -0,0 +1,24 @@ +from datetime import datetime + +class EnergyUsageResult: + """Contains local time, current power and the energy usage and runtime for today and for the current month.""" + + local_time: datetime + """Local time of the device.""" + current_power: int + """Current power in milliwatts (mW).""" + today_runtime: int + """Today runtime in minutes.""" + today_energy: int + """Today energy usage in watts (W).""" + month_runtime: int + """Current month runtime in minutes.""" + month_energy: int + """Current month energy usage in watts (W).""" + + def to_dict(self) -> dict: + """Gets all the properties of this result as a dictionary. + + Returns: + dict: The result as a dictionary. + """ diff --git a/tapo-py/tapo-py/tapo/types.pyi b/tapo-py/tapo-py/tapo/types.pyi deleted file mode 100644 index bd1bfc2..0000000 --- a/tapo-py/tapo-py/tapo/types.pyi +++ /dev/null @@ -1,108 +0,0 @@ -from enum import StrEnum - -class DefaultBrightnessState: - """Default brightness state.""" - - type: DefaultStateType - value: int - -class DefaultStateType(StrEnum): - """The type of the default state.""" - - Custom = "custom" - LastStates = "last_states" - -class DefaultPowerType(StrEnum): - """The type of the default power state.""" - - AlwaysOn = "always_on" - LastStates = "last_states" - -class UsageByPeriodResult: - """Usage by period result for today, the past 7 days, and the past 30 days.""" - - today: int - """Today.""" - past7: int - """Past 7 days.""" - past30: int - """Past 30 days.""" - -class DeviceUsageResult: - """Contains the time in use, the power consumption, and the energy savings of the device.""" - - time_usage: UsageByPeriodResult - """Time usage in minutes.""" - power_usage: UsageByPeriodResult - """Power usage in watt-hour (Wh).""" - saved_power: UsageByPeriodResult - """Saved power in watt-hour (Wh).""" - - def to_dict(self) -> dict: - """Gets all the properties of this result as a dictionary. - - Returns: - dict: The result as a dictionary. - """ - -class DeviceUsageEnergyMonitoringResult: - """Contains the time in use, the power consumption, and the energy savings of the device.""" - - time_usage: UsageByPeriodResult - """Time usage in minutes.""" - power_usage: UsageByPeriodResult - """Power usage in watt-hour (Wh).""" - saved_power: UsageByPeriodResult - """Saved power in watt-hour (Wh).""" - - def to_dict(self) -> dict: - """Gets all the properties of this result as a dictionary. - - Returns: - dict: The result as a dictionary. - """ - -class Color(StrEnum): - """List of preset colors as defined in the Google Home app.""" - - CoolWhite = "CoolWhite" - Daylight = "Daylight" - Ivory = "Ivory" - WarmWhite = "WarmWhite" - Incandescent = "Incandescent" - Candlelight = "Candlelight" - Snow = "Snow" - GhostWhite = "GhostWhite" - AliceBlue = "AliceBlue" - LightGoldenrod = "LightGoldenrod" - LemonChiffon = "LemonChiffon" - AntiqueWhite = "AntiqueWhite" - Gold = "Gold" - Peru = "Peru" - Chocolate = "Chocolate" - SandyBrown = "SandyBrown" - Coral = "Coral" - Pumpkin = "Pumpkin" - Tomato = "Tomato" - Vermilion = "Vermilion" - OrangeRed = "OrangeRed" - Pink = "Pink" - Crimson = "Crimson" - DarkRed = "DarkRed" - HotPink = "HotPink" - Smitten = "Smitten" - MediumPurple = "MediumPurple" - BlueViolet = "BlueViolet" - Indigo = "Indigo" - LightSkyBlue = "LightSkyBlue" - CornflowerBlue = "CornflowerBlue" - Ultramarine = "Ultramarine" - DeepSkyBlue = "DeepSkyBlue" - Azure = "Azure" - NavyBlue = "NavyBlue" - LightTurquoise = "LightTurquoise" - Aquamarine = "Aquamarine" - Turquoise = "Turquoise" - LightGreen = "LightGreen" - Lime = "Lime" - ForestGreen = "ForestGreen"