diff --git a/CHANGELOG.md b/CHANGELOG.md index 097a793..9e0c9b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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. diff --git a/tapo-py/tapo-py/tapo/requests/set_device_info/color.pyi b/tapo-py/tapo-py/tapo/requests/set_device_info/color.pyi index 04bdf1d..e78ea15 100644 --- a/tapo-py/tapo-py/tapo/requests/set_device_info/color.pyi +++ b/tapo-py/tapo-py/tapo/requests/set_device_info/color.pyi @@ -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.""" @@ -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.""" diff --git a/tapo/src/requests/set_device_info/color.rs b/tapo/src/requests/set_device_info/color.rs index f419e9b..bf8c26b 100644 --- a/tapo/src/requests/set_device_info/color.rs +++ b/tapo/src/requests/set_device_info/color.rs @@ -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 { - 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! { @@ -107,4 +111,4 @@ lazy_static! { map.insert(Color::ForestGreen, (120, 75, 0)); map }; -} \ No newline at end of file +} diff --git a/tapo/src/requests/set_device_info/color_light.rs b/tapo/src/requests/set_device_info/color_light.rs index 35410a4..5de2247 100644 --- a/tapo/src/requests/set_device_info/color_light.rs +++ b/tapo/src/requests/set_device_info/color_light.rs @@ -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);