Skip to content

Commit

Permalink
Fix relative only range capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
dext0r committed Oct 7, 2023
1 parent 07be1c0 commit cad5131
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions custom_components/yandex_smart_home/capability_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,27 @@ def range(self) -> (float, float, float):

def parameters(self) -> dict[str, Any]:
"""Return parameters for a devices request."""
if self.support_random_access:
range_min, range_max, range_precision = self.range
rv = {
'instance': self.instance,
'random_access': True,
'range': {
'min': range_min,
'max': range_max,
'precision': range_precision
}
}

if self.instance in const.RANGE_INSTANCE_TO_UNITS:
rv['unit'] = const.RANGE_INSTANCE_TO_UNITS[self.instance]

return rv

return {
range_min, range_max, range_precision = self.range
rv = {
'instance': self.instance,
'random_access': False,
'random_access': self.support_random_access
}

if self.instance in const.RANGE_INSTANCE_TO_UNITS:
rv['unit'] = const.RANGE_INSTANCE_TO_UNITS[self.instance]

if self.instance in [const.RANGE_INSTANCE_BRIGHTNESS,
const.RANGE_INSTANCE_HUMIDITY,
const.RANGE_INSTANCE_OPEN,
const.RANGE_INSTANCE_TEMPERATURE] or self.support_random_access:
rv['range'] = {
'min': range_min,
'max': range_max,
'precision': range_precision
}

return rv

def get_value(self) -> float | str | bool | None:
value = self._value

Expand Down

0 comments on commit cad5131

Please sign in to comment.