Skip to content

Commit

Permalink
Merge pull request #36 from RainerStaude/develop
Browse files Browse the repository at this point in the history
replace deprecated constants
  • Loading branch information
RainerStaude authored Apr 18, 2024
2 parents 5248f47 + 74de19e commit c10dab1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 60 deletions.
11 changes: 4 additions & 7 deletions const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

import re

from homeassistant.const import (
STATE_CLOSED,
STATE_OPEN,
)
from homeassistant.const import STATE_CLOSED, STATE_OPEN

from .pybecker.becker import (
COMMAND_HALT,
COMMAND_UP,
COMMAND_UP5,
COMMAND_DOWN,
COMMAND_DOWN5,
COMMAND_HALT,
COMMAND_RELEASE,
COMMAND_UP,
COMMAND_UP5,
)

DOMAIN = "becker"
Expand Down
96 changes: 44 additions & 52 deletions cover.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
"""Support for Becker RF covers."""

import logging

import time
import voluptuous as vol
from .travelcalculator import TravelCalculator

from homeassistant.core import callback
from homeassistant.exceptions import (
TemplateError,
)
import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.event import (
async_call_later,
TrackTemplate,
async_track_template_result,
)
from homeassistant.components.cover import (
PLATFORM_SCHEMA,
SUPPORT_CLOSE,
SUPPORT_CLOSE_TILT,
SUPPORT_OPEN,
SUPPORT_OPEN_TILT,
SUPPORT_STOP,
ATTR_POSITION,
ATTR_CURRENT_POSITION,
SUPPORT_SET_POSITION,
ATTR_POSITION,
PLATFORM_SCHEMA,
CoverEntity,
CoverEntityFeature,
)
from homeassistant.const import (
CONF_COVERS,
Expand All @@ -37,40 +19,50 @@
CONF_FRIENDLY_NAME,
CONF_VALUE_TEMPLATE,
)
from homeassistant.core import callback
from homeassistant.exceptions import TemplateError
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import (
TrackTemplate,
async_call_later,
async_track_template_result,
)
from homeassistant.helpers.restore_state import RestoreEntity

from .const import (
DOMAIN,
RECEIVE_MESSAGE,
CONF_CHANNEL,
DEVICE_CLASS,
CLOSED_POSITION,
OPEN_POSITION,
VENTILATION_POSITION,
INTERMEDIATE_POSITION,
CONF_REMOTE_ID,
CONF_TRAVELLING_TIME_DOWN,
CONF_TRAVELLING_TIME_UP,
CONF_INTERMEDIATE_POSITION_UP,
CONF_INTERMEDIATE_POSITION_DOWN,
COMMANDS,
CONF_CHANNEL,
CONF_INTERMEDIATE_DISABLE,
CONF_INTERMEDIATE_POSITION,
COMMANDS,
REMOTE_ID,
CONF_TILT_INTERMEDIATE,
CONF_INTERMEDIATE_POSITION_DOWN,
CONF_INTERMEDIATE_POSITION_UP,
CONF_REMOTE_ID,
CONF_TILT_BLIND,
CONF_TILT_INTERMEDIATE,
CONF_TILT_TIME_BLIND,
TILT_TIME,
TILT_RECEIVE_TIMEOUT,
TILT_FUNCTIONALITY,
CONF_TRAVELLING_TIME_DOWN,
CONF_TRAVELLING_TIME_UP,
DEVICE_CLASS,
DOMAIN,
INTERMEDIATE_POSITION,
OPEN_POSITION,
RECEIVE_MESSAGE,
REMOTE_ID,
TEMPLATE_UNKNOWN_STATES,
TEMPLATE_VALID_CLOSE,
TEMPLATE_VALID_OPEN,
TEMPLATE_UNKNOWN_STATES
TILT_FUNCTIONALITY,
TILT_RECEIVE_TIMEOUT,
TILT_TIME,
VENTILATION_POSITION,
)

from .rf_device import PyBecker
from .travelcalculator import TravelCalculator

_LOGGER = logging.getLogger(__name__)

COVER_FEATURES = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP
COVER_FEATURES = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP

COVER_SCHEMA = vol.Schema(
{
Expand Down Expand Up @@ -214,7 +206,7 @@ def __init__(
self._tilt_time_blind = tilt_time_blind
self._tilt_timeout = time.time()
if tilt_intermediate or tilt_blind:
self._cover_features |= SUPPORT_OPEN_TILT | SUPPORT_CLOSE_TILT
self._cover_features |= CoverEntityFeature.OPEN_TILT | CoverEntityFeature.CLOSE_TILT
if tilt_blind:
self._attr[TILT_FUNCTIONALITY] = str(CONF_TILT_BLIND)
self._attr[CONF_TILT_TIME_BLIND] = str(tilt_time_blind)
Expand All @@ -225,11 +217,11 @@ def __init__(
# Setup TravelCalculator
# todo enable set position and self_template
if not ((travel_time_down or travel_time_up) is None or self._template is not None):
self._cover_features |= SUPPORT_SET_POSITION
self._cover_features |= CoverEntityFeature.SET_POSITION

travel_time_down = travel_time_down or travel_time_up or 0
travel_time_up = travel_time_up or travel_time_down or 0
if self._cover_features & SUPPORT_SET_POSITION:
if self._cover_features & CoverEntityFeature.SET_POSITION:
self._attr[CONF_TRAVELLING_TIME_DOWN] = str(travel_time_down)
self._attr[CONF_TRAVELLING_TIME_UP] = str(travel_time_up)
self._tc = TravelCalculator(travel_time_down, travel_time_up)
Expand Down Expand Up @@ -312,15 +304,15 @@ def is_closed(self):
def is_opening(self):
"""Return if the cover is opening or not."""
action = False
if self._cover_features & SUPPORT_SET_POSITION:
if self._cover_features & CoverEntityFeature.SET_POSITION:
action = self._tc.is_opening()
return action

@property
def is_closing(self):
"""Return if the cover is closing or not."""
action = False
if self._cover_features & SUPPORT_SET_POSITION:
if self._cover_features & CoverEntityFeature.SET_POSITION:
action = self._tc.is_closing()
return action

Expand Down Expand Up @@ -404,18 +396,18 @@ def _travel_to_position(self, position):
def _travel_stop(self):
"""Stop TravelCalculator and update ha-state."""
self._tc.stop()
if not (self._cover_features & SUPPORT_SET_POSITION) and self._template is None:
if not (self._cover_features & CoverEntityFeature.SET_POSITION) and self._template is None:
self._tc.set_position(50)
_LOGGER.debug("%s stopped at position %s", self.name, self.current_cover_position)
self._update_scheduled_ha_state_callback(0)

def _update_scheduled_ha_state_callback(self, delay=None):
"""
Update ha-state callback
None: unsubscibe pending callback
None: unsubscribe pending callback
0: update now
> 0: update now and setup callback after delay later
"""
> 0: update now and setup callback after delay later.
""" # noqa: D205, D212
# unsubscribe outdated pending callbacks
self._callbacks.pop('update_ha', lambda: None)()
# Schedule callback to update ha-state at end of travel
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "becker",
"name": "Becker",
"documentation": "",
"version": "0.3.3",
"version": "0.3.4",
"requirements": [],
"dependencies": [],
"codeowners": ["@nicolasberthel", "@RainerStaude"]
Expand Down

0 comments on commit c10dab1

Please sign in to comment.