Skip to content

Commit

Permalink
Tweaks and Python support
Browse files Browse the repository at this point in the history
  • Loading branch information
mihai-dinculescu committed Dec 22, 2024
1 parent 133c466 commit 8c00e61
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ file. This change log follows the conventions of
#### Added

- Added functionality for controlling the alarm on the H100 hub via the `play_alarm` and `stop_alarm` methods in the `H100Handler`. Additionally, `get_supported_ringtone_list` is available to retrieve the list of supported ringtones for debugging purposes. (thanks to @kay)
- Added the ability to retrieve the color configuration (`hue`, `saturation`, `color_temperature`) for the `Color` enum values through the `get_color_config` method. (thanks to @WhySoBad)

#### Changed

Expand All @@ -19,6 +20,10 @@ file. This change log follows the conventions of

### Python

#### Added

- Added the ability to retrieve the color configuration (`hue`, `saturation`, `color_temperature`) for the `Color` enum values through the `get_color_config` method. (thanks to @WhySoBad)

#### Changed

- The internal implementation of `H100Handler`'s `get_child_device_list` has been updated to fetch all pages, not just the first one.
Expand Down
4 changes: 4 additions & 0 deletions tapo-py/tapo-py/tapo/requests/set_device_info/color.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
from typing import Tuple

class Color(str, Enum):
"""List of preset colors as defined in the Google Home app."""
Expand Down Expand Up @@ -44,3 +45,6 @@ class Color(str, Enum):
LightGreen = "LightGreen"
Lime = "Lime"
ForestGreen = "ForestGreen"

def get_color_config(self) -> Tuple[int, int, int]:
"""Get the `hue`, `saturation`, and `color_temperature` of the color."""
14 changes: 9 additions & 5 deletions tapo/src/requests/set_device_info/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@ pub enum Color {
ForestGreen,
}

#[cfg_attr(feature = "python", pyo3::pymethods)]
impl Color {
/// Get the [`crate::requests::ColorConfig`] for the color
pub fn get_color_config(&self) -> Option<ColorConfig> {
COLOR_MAP.get(self).cloned()
/// Get the [`crate::requests::ColorConfig`] of the color.
pub fn get_color_config(&self) -> ColorConfig {
COLOR_MAP
.get(self)
.cloned()
.unwrap_or_else(|| panic!("Failed to find the color definition of {self:?}"))
}
}

/// Triple-Tuple of hue, saturation and color temperature of a predefined color
/// Triple-tuple containing the `hue`, `saturation`, and `color_temperature` of a color.
pub type ColorConfig = (u16, u8, u16);

lazy_static! {
Expand Down Expand Up @@ -107,4 +111,4 @@ lazy_static! {
map.insert(Color::ForestGreen, (120, 75, 0));
map
};
}
}
4 changes: 1 addition & 3 deletions tapo/src/requests/set_device_info/color_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ impl ColorLightSetDeviceInfoParams {
///
/// * `color` - one of [crate::requests::Color]
pub fn color(mut self, color: Color) -> Self {
let (hue, saturation, color_temperature) = color
.get_color_config()
.expect(format!("Failed to find the color definition for {color:?}").as_str());
let (hue, saturation, color_temperature) = color.get_color_config();

self.hue = Some(hue);
self.saturation = Some(saturation);
Expand Down

0 comments on commit 8c00e61

Please sign in to comment.