8000 Add device fixture for P316M(US) by TheLinuxGuy · Pull Request #1561 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ The following devices have been tested and confirmed as working. If your device
### Supported Tapo[^1] devices

- **Plugs**: P100, P110, P110M, P115, P125M, P135, TP10, TP15
- **Power Strips**: P210M, P300, P304M, P306, TP25
- **Power Strips**: P210M, P300, P304M, P306, P316M, TP25
- **Wall Switches**: S210, S220, S500D, S505, S505D
- **Bulbs**: L510B, L510E, L530B, L530E, L535E, L630
- **Light Strips**: L900-10, L900-5, L920-5, L930-5
Expand Down
2 changes: 2 additions & 0 deletions SUPPORTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ All Tapo devices require authentication.<br>Hub-Connected Devices may work acros
- Hardware: 1.0 (UK) / Firmware: 1.0.3
- **P306**
- Hardware: 1.0 (US) / Firmware: 1.1.2
- **P316M**
- Hardware: 1.6 (US) / Firmware: 1.0.5
- **TP25**
- Hardware: 1.0 (US) / Firmware: 1.0.2

Expand Down
6 changes: 6 additions & 0 deletions kasa/smart/modules/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,10 @@ async def get_monthly_stats(
async def _check_supported(self) -> bool:
"""Additional check to see if the module is supported by the device."""
# Energy module is not supported on P304M parent device
# P316M powerstrip does not have 'device_on' key in sys_info.
if (
"device_on" not in self._device.sys_info
and self._device.sys_info.get("model") == "P316M"
):
return True
return "device_on" in self._device.sys_info
Comment on lines 166 to 173
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this check is only done to avoid initializing energy module for the main device on P304M as it only reports this information on the child sockets. I think this was an easy solution as the main device cannot be switched on and off, but this check should to my understanding also work for your P316M.

Maybe it's just the cli that needs adjustment for devices that have individual sockets with emeter?
In any case, I would suggest that we get this PR first merged without changes to emeter & tackle that issue in a separate PR.

7 changes: 6 additions & 1 deletion kasa/smart/modules/powerprotection.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def overloaded(self) -> bool:
@property
def enabled(self) -> bool:
"""Return True if child protection is enabled."""
return self.data["get_protection_power"]["enabled"]
gp = self.data["get_protection_power"]
return gp.get("enabled") or gp.get("protection_enabled")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return gp.get("enabled") or gp.get("protection_enabled")
return gp.get("enabled", gp.get("protection_enabled"))


async def set_enabled(self, enabled: bool, *, threshold: int | None = None) -> dict:
"""Set power protection enabled.
Expand All @@ -74,6 +75,10 @@ async def set_enabled(self, enabled: bool, *, threshold: int | None = None) -> d
)

params = {**self.data["get_protection_power"], "enabled": enabled}
# If "enabled" is not used by the device, use "protection_enabled"
if "protection_enabled" in self.data["get_protection_power"]:
params["protection_enabled"] = enabled
params.pop("enabled", None)
Comment on lines 77 to +81
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
params = {**self.data["get_protection_power"], "enabled": enabled}
# If "enabled" is not used by the device, use "protection_enabled"
if "protection_enabled" in self.data["get_protection_power"]:
params["protection_enabled"] = enabled
params.pop("enabled", None)
enabled_key = next(k for k in self.data["get_protection_power"].keys() if "enabled" in k)
params = {**self.data["get_protection_power"], enabled_key: enabled}

How about something like this?

if threshold is not None:
params["protection_power"] = threshold
return await self.call("set_protection_power", params)
Expand Down
2 changes: 1 addition & 1 deletion tests/device_fixtures.py
6D40
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
}
SWITCHES = {*SWITCHES_IOT, *SWITCHES_SMART}
STRIPS_IOT = {"HS107", "HS300", "KP303", "KP200", "KP400", "EP40"}
STRIPS_SMART = {"P300", "P304M", "TP25", "EP40M", "P210M", "P306"}
STRIPS_SMART = {"P300", "P304M", "TP25", "EP40M", "P210M", "P306", "P316M"}
STRIPS = {*STRIPS_IOT, *STRIPS_SMART}

DIMMERS_IOT = {"ES20M", "HS220", "KS220", "KS220M", "KS230", "KP405"}
Expand Down
Loading
Loading
0