Skip to content

Commit

Permalink
decorator id
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG committed Nov 9, 2022
1 parent b5a2940 commit 8dab28c
Showing 1 changed file with 8 additions and 6 deletions.
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

0 comments on commit 8dab28c

Please sign in to comment.