Skip to content

Commit

Permalink
Minor pretty-printing changes (#1754)
Browse files Browse the repository at this point in the history
* Implement `__str__` for genericmiotstatus for prettier printing
(prints only the id and the value)
* Don't show raw data in cloud repr
  • Loading branch information
rytilahti committed Mar 5, 2023
1 parent 812dcbd commit 2e150a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion miio/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CloudDeviceInfo(BaseModel):
is_online: bool = Field(alias="isOnline")
rssi: int

_raw_data: dict
_raw_data: dict = Field(repr=False)

@property
def is_child(self):
Expand Down
10 changes: 10 additions & 0 deletions miio/integrations/genericmiot/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,19 @@ def __dir__(self) -> Iterable[str]:
return list(super().__dir__()) + list(self._data_by_normalized_name.keys())

def __repr__(self):
"""Return string representation of the status."""
s = f"<{self.__class__.__name__}"
for name, value in self.property_dict().items():
s += f" {name}={value}"
s += ">"

return s

def __str__(self):
"""Return simplified string representation of the status."""
s = f"<{self.__class__.__name__}"
for name, value in self.property_dict().items():
s += f" {name}={value.pretty_value}"
s += ">"

return s

0 comments on commit 2e150a2

Please sign in to comment.