Skip to content
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

Use __qualname__ to make ids unique for settings and sensors #1589

Merged
merged 1 commit into from Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions miio/devicestatus.py
Expand Up @@ -143,7 +143,8 @@ def sensor(name: str, *, unit: str = "", **kwargs):
"""

def decorator_sensor(func):
property_name = func.__name__
property_name = str(func.__name__)
qualified_name = str(func.__qualname__)

def _sensor_type_for_return_type(func):
rtype = get_type_hints(func).get("return")
Expand All @@ -157,8 +158,8 @@ def _sensor_type_for_return_type(func):

sensor_type = _sensor_type_for_return_type(func)
descriptor = SensorDescriptor(
id=str(property_name),
property=str(property_name),
id=qualified_name,
property=property_name,
name=name,
unit=unit,
type=sensor_type,
Expand Down Expand Up @@ -196,14 +197,15 @@ def setting(
"""

def decorator_setting(func):
property_name = func.__name__
property_name = str(func.__name__)
qualified_name = str(func.__qualname__)

if setter is None and setter_name is None:
raise Exception("Either setter or setter_name needs to be defined")

common_values = {
"id": str(property_name),
"property": str(property_name),
"id": qualified_name,
"property": property_name,
"name": name,
"unit": unit,
"setter": setter,
Expand Down