Bases: CoordinatorEntity[SunRiserCoordinator], NumberEntity
Number entity for pwm#X#fixed — the value used when manager is set to 'fixed'.
Source code in custom_components/sunriser/number.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 | class SunRiserPWMFixedNumber(CoordinatorEntity[SunRiserCoordinator], NumberEntity):
"""Number entity for pwm#X#fixed — the value used when manager is set to 'fixed'."""
_attr_has_entity_name = True
_attr_translation_key = "fixed_value"
_attr_entity_category = EntityCategory.CONFIG
# Only relevant when manager is set to "fixed"; disabled by default to reduce noise.
_attr_entity_registry_enabled_default = False
_attr_mode = NumberMode.SLIDER
_attr_native_min_value = 0
_attr_native_max_value = PWM_MAX
_attr_native_step = 1
def __init__(
self,
coordinator: SunRiserCoordinator,
entry: ConfigEntry,
pwm_num: int,
) -> None:
super().__init__(coordinator)
self._pwm_num = pwm_num
self._attr_unique_id = f"{entry.entry_id}_pwm_{pwm_num}_fixed"
self._attr_translation_placeholders = {"channel": coordinator.pwm_name(pwm_num)}
self._attr_device_info = coordinator.device_info
@property
def native_value(self) -> float:
return float(self.coordinator.config.get(f"pwm#{self._pwm_num}#fixed") or 0)
async def async_set_native_value(self, value: float) -> None:
int_value = int(value)
await self.coordinator.async_set_config(
{f"pwm#{self._pwm_num}#fixed": int_value}
)
self.coordinator.config[f"pwm#{self._pwm_num}#fixed"] = int_value
|