1 """Shade data for the Hunter Douglas PowerView integration."""
3 from __future__
import annotations
5 from dataclasses
import fields
8 from aiopvapi.resources.model
import PowerviewData
9 from aiopvapi.resources.shade
import BaseShade, ShadePosition
11 from .util
import async_map_data_by_id
13 POSITION_FIELDS = [field
for field
in fields(ShadePosition)
if field.name !=
"velocity"]
17 """Copy position data from source to target for None values only."""
18 for field
in POSITION_FIELDS:
19 if (value := getattr(source, field.name))
is not None:
20 setattr(target, field.name, value)
24 """Coordinate shade data between multiple api calls."""
27 """Init the shade data."""
28 self.
_raw_data_by_id_raw_data_by_id: dict[int, dict[str | int, Any]] = {}
30 self.positions: dict[int, ShadePosition] = {}
33 """Get data for the shade."""
37 """Get data for all shades."""
41 """Get specific shade from the coordinator."""
45 """Get positions for a shade."""
46 if shade_id
not in self.positions:
47 shade_position = ShadePosition()
51 self.positions[shade_id] = shade_position
52 return self.positions[shade_id]
55 """Process an update from the group data."""
60 """Store data from the all shades endpoint.
62 This does not update the shades or positions (self.positions)
63 as the data may be stale. update_from_group_data
64 with a shade_id will update a specific shade
71 """Update a single shades position."""
75 """Update a single shades velocity."""
79 if shade_data.velocity
is not None:
None update_from_group_data(self, int shade_id)
dict[int, dict[str|int, Any]] get_all_raw_data(self)
None update_shade_position(self, int shade_id, ShadePosition new_position)
None store_group_data(self, PowerviewData shade_data)
dict[str|int, Any] get_raw_data(self, int shade_id)
None update_shade_velocity(self, int shade_id, ShadePosition shade_data)
BaseShade get_shade(self, int shade_id)
ShadePosition get_shade_position(self, int shade_id)
web.Response get(self, web.Request request, str config_key)
ShadePosition copy_position_data(ShadePosition source, ShadePosition target)
def async_map_data_by_id(Iterable[dict[str|int, Any]] data)