Skip to content

Commit

Permalink
Try to make cover position consistent across enet and HA
Browse files Browse the repository at this point in the history
  • Loading branch information
mnordseth committed Jun 6, 2023
1 parent b8d9fbf commit 15582a3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions custom_components/enet/cover.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Enet Smart Home cover / blinds support"""

import logging
import math
from homeassistant.components.cover import (
ATTR_POSITION,
# ATTR_TILT_POSITION,
Expand Down Expand Up @@ -69,9 +70,9 @@ def is_closed(self):
def current_cover_position(self):
"""Return current position of cover tilt.
None is unknown, 0 is closed, 100 is fully open.
None is unknown, 0 is fully open, 100 is closed.
"""
return int(float((100 - self.channel.state) / 100) * 255)
return math.ceil(float(self.channel.state / 100) * 255)

async def async_added_to_hass(self):
"""Subscribe entity to updates when added to hass."""
Expand All @@ -91,6 +92,6 @@ async def async_open_cover(self, **kwargs) -> None:

async def async_set_cover_position(self, **kwargs) -> None:
"""Move the cover to a specific position."""
enet_position = 100 - int(float(kwargs[ATTR_POSITION]) / 255 * 100)
enet_position = math.ceil(float(kwargs[ATTR_POSITION]) / 255 * 100)
await self.channel.set_value(enet_position)
self.async_write_ha_state()

0 comments on commit 15582a3

Please sign in to comment.