Skip to content

Commit

Permalink
Revert velocity change in powerview (home-assistant#114337)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Mar 28, 2024
1 parent bec45da commit a07dc85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/hunterdouglas_powerview/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def store_velocity(
value: float | None,
) -> None:
"""Store the desired shade velocity in the coordinator."""
coordinator.data.update_shade_position(shade_id, ShadePosition(velocity=value))
coordinator.data.update_shade_velocity(shade_id, ShadePosition(velocity=value))


NUMBERS: Final = (
Expand Down
13 changes: 9 additions & 4 deletions homeassistant/components/hunterdouglas_powerview/shade_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@

_LOGGER = logging.getLogger(__name__)

POSITION_FIELDS = fields(ShadePosition)
POSITION_FIELDS = [field for field in fields(ShadePosition) if field.name != "velocity"]


def copy_position_data(source: ShadePosition, target: ShadePosition) -> ShadePosition:
"""Copy position data from source to target for None values only."""
# the hub will always return a velocity of 0 on initial connect,
# separate definition to store consistent value in HA
# this value is purely driven from HA
for field in POSITION_FIELDS:
if (value := getattr(source, field.name)) is not None:
setattr(target, field.name, value)
Expand Down Expand Up @@ -76,3 +73,11 @@ def store_group_data(self, shade_data: PowerviewData) -> None:
def update_shade_position(self, shade_id: int, new_position: ShadePosition) -> None:
"""Update a single shades position."""
copy_position_data(new_position, self.get_shade_position(shade_id))

def update_shade_velocity(self, shade_id: int, shade_data: ShadePosition) -> None:
"""Update a single shades velocity."""
# the hub will always return a velocity of 0 on initial connect,
# separate definition to store consistent value in HA
# this value is purely driven from HA
if shade_data.velocity is not None:
self.get_shade_position(shade_id).velocity = shade_data.velocity

0 comments on commit a07dc85

Please sign in to comment.