-
Notifications
You must be signed in to change notification settings - Fork 0
/
number.py
111 lines (76 loc) · 3.55 KB
/
number.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""Platform for number integration."""
from __future__ import annotations
import logging
from homeassistant.components.number import NumberEntity
from homeassistant.components.number.const import NumberMode
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from . import DysonEntity
from .const import DOMAIN
from .dyson import DysonPureCool
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback,) -> None:
"""Set up Dyson Pure Cool numbner from a config entry."""
device = hass.data[DOMAIN][config_entry.entry_id]
coordinator = hass.data[DOMAIN][f"{config_entry.entry_id}_coordinator"]
async_add_entities([
DysonOscillateLowerEntity(coordinator, device),
DysonOscillateUpperEntity(coordinator, device)
])
class DysonOscillateLowerEntity(NumberEntity, DysonEntity):
"""Representation of a dyson number entity for the lower boundary of the oscillation."""
_attr_entity_category = EntityCategory.CONFIG
def __init__(self, coordinator: DataUpdateCoordinator, device: DysonPureCool):
"""Initialize a dyson number entity for the lower boundary of the oscillation."""
super().__init__(coordinator, device, "Oscillation lower boundary", "osal")
self._attr_mode = NumberMode.BOX
self._attr_device_class = None
self._attr_native_min_value = 5
self._attr_native_max_value = 355
self._attr_native_step = 1
self._attr_icon = "mdi:rotate-left"
@property
def native_value(self) -> float | None:
"""Return the value reported by the number."""
return self._device.oscillate_lower
def set_native_value(self, value: float) -> None:
"""Update the current value."""
self._device.oscillate(
self._device.is_on,
int(value),
self._device.oscillate_upper
)
@property
def available(self) -> bool:
"""Return True if entity is available."""
return self._device.is_on and self._device.oscillating
class DysonOscillateUpperEntity(NumberEntity, DysonEntity):
"""Representation of a dyson number entity for the upper boundary of the oscillation."""
_attr_entity_category = EntityCategory.CONFIG
def __init__(self, coordinator: DataUpdateCoordinator, device: DysonPureCool):
"""Initialize a dyson number entity for the upper boundary of the oscillation."""
super().__init__(coordinator, device, "Oscillation upper boundary", "osau")
self._attr_mode = NumberMode.BOX
self._attr_device_class = None
self._attr_native_min_value = 5
self._attr_native_max_value = 355
self._attr_native_step = 1
self._attr_icon = "mdi:rotate-right"
@property
def native_value(self) -> float | None:
"""Return the value reported by the number."""
return self._device.oscillate_upper
def set_native_value(self, value: float) -> None:
"""Update the current value."""
self._device.oscillate(
self._device.is_on,
self._device.oscillate_lower,
int(value)
)
@property
def available(self) -> bool:
"""Return True if entity is available."""
return self._device.is_on and self._device.oscillating