-
-
Notifications
You must be signed in to change notification settings - Fork 239
Add common Thermostat module #977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
018931a
Add common thermostat module
sdb9696 9fa3c25
Merge remote-tracking branch 'upstream/master' into feat/thermostat_m…
sdb9696 1fb10ce
Add type hints for ANN check
sdb9696 8802e90
Merge remote-tracking branch 'upstream/master' into feat/thermostat_m…
sdb9696 73af2b9
Simplify interface and use get_feature for ranges
sdb9696 616f604
Only add thermostat module if both control and sensor present
sdb9696 de458e9
Move temperature sensor features back to sensor
sdb9696 54641e1
Move features back to modules and fix ordering
sdb9696 ff6bb8d
Move _target_temperature_range to bottom
sdb9696 e69fa88
Update kasa/__init__.py
sdb9696 891e797
Merge branch 'master' into feat/thermostat_module
sdb9696 4cc826c
Merge remote-tracking branch 'upstream/master' into feat/thermostat_m…
sdb9696 f25d08a
Fix tests and remove _target_temperature_range from common interface
sdb9696 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """Interact with a TPLink Thermostat.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from enum import Enum | ||
| from typing import Annotated, Literal | ||
|
|
||
| from ..module import FeatureAttribute, Module | ||
|
|
||
|
|
||
| class ThermostatState(Enum): | ||
| """Thermostat state.""" | ||
|
|
||
| Heating = "heating" | ||
| Calibrating = "progress_calibration" | ||
| Idle = "idle" | ||
| Off = "off" | ||
| Unknown = "unknown" | ||
|
|
||
|
|
||
| class Thermostat(Module, ABC): | ||
| """Base class for TP-Link Thermostat.""" | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def state(self) -> bool: | ||
| """Return thermostat state.""" | ||
|
|
||
| @abstractmethod | ||
| async def set_state(self, enabled: bool) -> dict: | ||
| """Set thermostat state.""" | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def mode(self) -> ThermostatState: | ||
| """Return thermostat state.""" | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def target_temperature(self) -> Annotated[float, FeatureAttribute()]: | ||
| """Return target temperature.""" | ||
|
|
||
| @abstractmethod | ||
| async def set_target_temperature( | ||
| self, target: float | ||
| ) -> Annotated[dict, FeatureAttribute()]: | ||
| """Set target temperature.""" | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def temperature(self) -> Annotated[float, FeatureAttribute()]: | ||
| """Return current humidity in percentage.""" | ||
| return self._device.sys_info["current_temp"] | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def temperature_unit(self) -> Literal["celsius", "fahrenheit"]: | ||
| """Return current temperature unit.""" | ||
|
|
||
| @abstractmethod | ||
| async def set_temperature_unit( | ||
| self, unit: Literal["celsius", "fahrenheit"] | ||
| ) -> dict: | ||
| """Set the device temperature unit.""" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| """Module for a Thermostat.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Annotated, Literal | ||
|
|
||
| from ...feature import Feature | ||
| from ...interfaces.thermostat import Thermostat as ThermostatInterface | ||
| from ...interfaces.thermostat import ThermostatState | ||
| from ...module import FeatureAttribute, Module | ||
| from ..smartmodule import SmartModule | ||
|
|
||
|
|
||
| class Thermostat(SmartModule, ThermostatInterface): | ||
| """Implementation of a Thermostat.""" | ||
|
|
||
| @property | ||
| def _all_features(self) -> dict[str, Feature]: | ||
| """Get the features for this module and any sub modules.""" | ||
| ret: dict[str, Feature] = {} | ||
| if temp_control := self._device.modules.get(Module.TemperatureControl): | ||
| ret.update(**temp_control._module_features) | ||
| if temp_sensor := self._device.modules.get(Module.TemperatureSensor): | ||
| ret.update(**temp_sensor._module_features) | ||
| return ret | ||
|
|
||
| def query(self) -> dict: | ||
| """Query to execute during the update cycle.""" | ||
| return {} | ||
|
|
||
| @property | ||
| def state(self) -> bool: | ||
| """Return thermostat state.""" | ||
| return self._device.modules[Module.TemperatureControl].state | ||
|
|
||
| async def set_state(self, enabled: bool) -> dict: | ||
| """Set thermostat state.""" | ||
| return await self._device.modules[Module.TemperatureControl].set_state(enabled) | ||
|
|
||
| @property | ||
| def mode(self) -> ThermostatState: | ||
| """Return thermostat state.""" | ||
| return self._device.modules[Module.TemperatureControl].mode | ||
|
|
||
| @property | ||
| def target_temperature(self) -> Annotated[float, FeatureAttribute()]: | ||
| """Return target temperature.""" | ||
| return self._device.modules[Module.TemperatureControl].target_temperature | ||
|
|
||
| async def set_target_temperature( | ||
| self, target: float | ||
| ) -> Annotated[dict, FeatureAttribute()]: | ||
| """Set target temperature.""" | ||
| return await self._device.modules[ | ||
| Module.TemperatureControl | ||
| ].set_target_temperature(target) | ||
|
|
||
| @property | ||
| def temperature(self) -> Annotated[float, FeatureAttribute()]: | ||
| """Return current humidity in percentage.""" | ||
| return self._device.modules[Module.TemperatureSensor].temperature | ||
|
|
||
| @property | ||
| def temperature_unit(self) -> Literal["celsius", "fahrenheit"]: | ||
| """Return current temperature unit.""" | ||
| return self._device.modules[Module.TemperatureSensor].temperature_unit | ||
|
|
||
| async def set_temperature_unit( | ||
| self, unit: Literal["celsius", "fahrenheit"] | ||
| ) -> dict: | ||
| """Set the device temperature unit.""" | ||
| return await self._device.modules[ | ||
| Module.TemperatureSensor | ||
| ].set_temperature_unit(unit) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.