Skip to content

Commit

Permalink
Merge branch 'feature/setposition' of https://github.com/Ginxo/meross…
Browse files Browse the repository at this point in the history
…-homeassistant into development

# Conflicts:
#	custom_components/meross_cloud/manifest.json
  • Loading branch information
albertogeniola committed Apr 25, 2024
2 parents 5a5e82e + 8de0937 commit fd03d6c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions custom_components/meross_cloud/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
from meross_iot.model.http.device import HttpDeviceInfo

# Conditional Light import with backwards compatibility
from homeassistant.components.cover import CoverEntity, CoverEntityFeature, CoverDeviceClass
from homeassistant.components.cover import (
CoverEntity,
CoverEntityFeature,
CoverDeviceClass,
ATTR_POSITION,
)

from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from . import MerossDevice
Expand Down Expand Up @@ -128,7 +134,7 @@ def supported_features(self):
"""Flag supported features."""
# So far, the Roller Shutter RST100 supports position, but it looks like it is fake and not reliable.
# So we don't support that on HA neither.
return CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
return CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP | CoverEntityFeature.SET_POSITION

@property
def current_cover_position(self):
Expand All @@ -148,6 +154,13 @@ def is_opening(self):
status = self._device.get_status(channel=self._channel_id)
return status == RollerShutterState.OPENING

async def async_set_cover_position(self, position: int):
await self._device.async_set_position(position=position, channel=self._channel_id)

def set_cover_position(self, **kwargs):
position = round(kwargs.get(ATTR_POSITION) or 0)
self.hass.async_add_executor_job(self.async_set_cover_position, int(position))


async def async_setup_entry(hass: HomeAssistantType, config_entry, async_add_entities):
def entity_adder_callback():
Expand Down

0 comments on commit fd03d6c

Please sign in to comment.