8000 Simplify device __repr__ by rytilahti · Pull Request #805 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Simplify device __repr__ #805

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 2 commits into from
Mar 5, 2024
Merged
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
6 changes: 1 addition & 5 deletions kasa/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,4 @@ async def set_alias(self, alias: str):
def __repr__(self):
if self._last_update is None:
return f"<{self.device_type} at {self.host} - update() needed>"
return (
f"<{self.device_type} model {self.model} at {self.host}"
f" ({self.alias}), is_on: {self.is_on}"
f" - dev specific: {self.state_information}>"
)
return f"<{self.device_type} at {self.host} - {self.alias} ({self.model})>"
2 changes: 1 addition & 1 deletion kasa/smart/smartchilddevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ def device_type(self) -> DeviceType:
return dev_type

def __repr__(self):
return f"<ChildDevice {self.alias} of {self._parent}>"
return f"<{self.device_type} {self.alias} ({self.model}) of {self._parent}>"
2 changes: 1 addition & 1 deletion kasa/tests/test_smartdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ async def test_mac(dev):
async def test_representation(dev):
import re

pattern = re.compile("<.* model .* at .* (.*), is_on: .* - dev specific: .*>")
pattern = re.compile("<DeviceType\..+ at .+? - .*? \(.+?\)>")
assert pattern.match(str(dev))


Expand Down
0