Skip to content

Commit

Permalink
Replace overheated with the three new fields for plugs (#254)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Dinculescu <[email protected]>
  • Loading branch information
padenot and mihai-dinculescu committed Aug 26, 2024
1 parent 8c7f5d9 commit c0d006e
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 16 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ file. This change log follows the conventions of

## [Rust Unreleased][Unreleased]

### Changed

- To align with the latest API updates, the `overheated` field for plugs has been replaced by three enums: `overcurrent_status`, `overheat_status`, and `power_protection_status` (thanks to @padenot).

## [Python Unreleased][Unreleased]

### Changed

- To align with the latest API updates, the `overheated` field for plugs has been replaced by three enums: `overcurrent_status`, `overheat_status`, and `power_protection_status`.

## [Rust v0.7.12][v0.7.12] - 2024-06-27

### Changed
Expand Down
10 changes: 7 additions & 3 deletions tapo-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ use tapo::responses::{
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,
DeviceUsageResult, EnergyDataResult, EnergyUsageResult, KE100Result, OvercurrentStatus,
OverheatStatus, PlugState, PowerProtectionStatus, S200BResult, Status, T100Result, T110Result,
T300Result, T31XResult, TemperatureUnit, TemperatureUnitKE100, UsageByPeriodResult,
WaterLeakStatus,
};

#[pymodule]
Expand Down Expand Up @@ -49,6 +50,9 @@ fn tapo_py(py: Python, module: &Bound<'_, PyModule>) -> PyResult<()> {
responses.add_class::<DeviceUsageResult>()?;
responses.add_class::<EnergyDataResult>()?;
responses.add_class::<EnergyUsageResult>()?;
responses.add_class::<OvercurrentStatus>()?;
responses.add_class::<OverheatStatus>()?;
responses.add_class::<PowerProtectionStatus>()?;
responses.add_class::<UsageByPeriodResult>()?;

// responses: device info: color light
Expand Down
1 change: 0 additions & 1 deletion tapo-py/tapo-py/tapo/responses/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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 *
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .color_light_result import *
from .default_state import *
from .generic_result import *
from .hub_result import *
from .light_result import *
from .plug_result import *
from .power_status import *
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional

from tapo.responses.default_state import DefaultStateType
from tapo.responses.device_info_result.default_state import DefaultStateType

class DeviceInfoColorLightResult:
"""Device info of Tapo L530, L630 and L900. Superset of `GenericDeviceInfoResult`."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from typing import Optional

from tapo.responses import DefaultStateType
from tapo.responses.device_info_result.default_state import DefaultStateType
from tapo.responses.device_info_result.power_status import (
OvercurrentStatus,
OverheatStatus,
PowerProtectionStatus,
)

class DeviceInfoPlugResult:
"""Device info of Tapo P100, P105, P110 and P115. Superset of `GenericDeviceInfoResult`."""
Expand Down Expand Up @@ -34,7 +39,9 @@ class DeviceInfoPlugResult:
# 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."""
overheated: bool
overcurrent_status: OvercurrentStatus
overheat_status: OverheatStatus
power_protection_status: PowerProtectionStatus

def to_dict(self) -> dict:
"""Gets all the properties of this result as a dictionary.
Expand Down
14 changes: 14 additions & 0 deletions tapo-py/tapo-py/tapo/responses/device_info_result/power_status.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from enum import Enum

class OvercurrentStatus(str, Enum):
Lifted = "lifted"
Normal = "normal"

class OverheatStatus(str, Enum):
CoolDown = "cool_down"
Normal = "normal"
Overheated = "overheated"

class PowerProtectionStatus(str, Enum):
Normal = "normal"
Overloaded = "overloaded"
9 changes: 1 addition & 8 deletions tapo/src/responses/child_device_list_power_strip_result.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};

use crate::error::Error;
use crate::responses::device_info_result::OverheatStatus;
use crate::responses::{decode_value, DecodableResultExt, TapoResponseExt};

/// Power Strip child device list result.
Expand Down Expand Up @@ -78,11 +79,3 @@ pub enum AutoOffStatus {
On,
Off,
}

/// Overheat Status.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[allow(missing_docs)]
pub enum OverheatStatus {
Normal,
}
2 changes: 2 additions & 0 deletions tapo/src/responses/device_info_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod generic;
mod hub;
mod light;
mod plug;
mod power_status;
mod power_strip;
mod rgb_light_strip;
mod rgbic_light_strip;
Expand All @@ -14,6 +15,7 @@ pub use generic::*;
pub use hub::*;
pub use light::*;
pub use plug::*;
pub use power_status::*;
pub use power_strip::*;
pub use rgb_light_strip::*;
pub use rgbic_light_strip::*;
7 changes: 6 additions & 1 deletion tapo/src/responses/device_info_result/plug.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use serde::{Deserialize, Serialize};

use crate::error::Error;
use crate::responses::device_info_result::{
OvercurrentStatus, OverheatStatus, PowerProtectionStatus,
};
use crate::responses::{decode_value, DecodableResultExt, DefaultStateType, TapoResponseExt};

/// Device info of Tapo P100, P105, P110 and P115. Superset of [`crate::responses::DeviceInfoGenericResult`].
Expand Down Expand Up @@ -41,7 +44,9 @@ pub struct DeviceInfoPlugResult {
//
/// The default state of a device to be used when internet connectivity is lost after a power cut.
pub default_states: DefaultPlugState,
pub overheated: bool,
pub overcurrent_status: OvercurrentStatus,
pub overheat_status: OverheatStatus,
pub power_protection_status: PowerProtectionStatus,
}

#[cfg(feature = "python")]
Expand Down
29 changes: 29 additions & 0 deletions tapo/src/responses/device_info_result/power_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "python", pyo3::prelude::pyclass(get_all))]
#[allow(missing_docs)]
pub enum OvercurrentStatus {
Lifted,
Normal,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "python", pyo3::prelude::pyclass(get_all))]
#[allow(missing_docs)]
pub enum OverheatStatus {
CoolDown,
Normal,
Overheated,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "python", pyo3::prelude::pyclass(get_all))]
#[allow(missing_docs)]
pub enum PowerProtectionStatus {
Normal,
Overloaded,
}

0 comments on commit c0d006e

Please sign in to comment.