Skip to content

Commit

Permalink
Rename properties to descriptors for devicestatus
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed Oct 23, 2023
1 parent 9b17d90 commit 4513f0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions miio/devicestatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __repr__(self):
s += ">"
return s

def properties(self) -> Dict[str, PropertyDescriptor]:
def descriptors(self) -> Dict[str, PropertyDescriptor]:
"""Return the dict of sensors exposed by the status container.
Use @sensor and @setting decorators to define properties.
Expand All @@ -101,7 +101,7 @@ def settings(self) -> Dict[str, PropertyDescriptor]:
# TODO: this is not probably worth having, remove?
return {
prop.id: prop
for prop in self.properties().values()
for prop in self.descriptors().values()
if prop.access & AccessFlags.Write
}

Expand All @@ -117,7 +117,7 @@ def embed(self, name: str, other: "DeviceStatus"):
self._embedded[name] = other
other._parent = self # type: ignore[attr-defined]

for property_name, prop in other.properties().items():
for property_name, prop in other.descriptors().items():
final_name = f"{name}__{property_name}"

self._descriptors[final_name] = attr.evolve(
Expand All @@ -132,7 +132,7 @@ def __dir__(self) -> Iterable[str]:
def __cli_output__(self) -> str:
"""Return a CLI formatted output of the status."""
out = ""
for descriptor in self.properties().values():
for descriptor in self.descriptors().values():
try:
value = getattr(self, descriptor.status_attribute)
except KeyError:
Expand Down
8 changes: 4 additions & 4 deletions miio/tests/test_devicestatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def unknown(self):
pass

status = DecoratedProps()
sensors = status.properties()
sensors = status.descriptors()
assert len(sensors) == 3

all_kwargs = sensors["all_kwargs"]
Expand Down Expand Up @@ -274,19 +274,19 @@ def sub_sensor(self):
return "sub"

main = MainStatus()
assert len(main.properties()) == 1
assert len(main.descriptors()) == 1

sub = SubStatus()
main.embed("SubStatus", sub)
sensors = main.properties()
sensors = main.descriptors()
assert len(sensors) == 2
assert sub._parent == main

assert getattr(main, sensors["main_sensor"].status_attribute) == "main"
assert getattr(main, sensors["SubStatus__sub_sensor"].status_attribute) == "sub"

with pytest.raises(KeyError):
main.properties()["nonexisting_sensor"]
main.descriptors()["nonexisting_sensor"]

assert (
repr(main)
Expand Down

0 comments on commit 4513f0d

Please sign in to comment.