mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Improve support for homematic garage covers (#35350)
This commit is contained in:
parent
06e977b444
commit
0edd7302d5
@ -25,6 +25,7 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from .const import (
|
from .const import (
|
||||||
ATTR_ADDRESS,
|
ATTR_ADDRESS,
|
||||||
ATTR_CHANNEL,
|
ATTR_CHANNEL,
|
||||||
|
ATTR_DEVICE_TYPE,
|
||||||
ATTR_DISCOVER_DEVICES,
|
ATTR_DISCOVER_DEVICES,
|
||||||
ATTR_DISCOVERY_TYPE,
|
ATTR_DISCOVERY_TYPE,
|
||||||
ATTR_ERRORCODE,
|
ATTR_ERRORCODE,
|
||||||
@ -99,6 +100,7 @@ DEVICE_SCHEMA = vol.Schema(
|
|||||||
vol.Required(ATTR_NAME): cv.string,
|
vol.Required(ATTR_NAME): cv.string,
|
||||||
vol.Required(ATTR_ADDRESS): cv.string,
|
vol.Required(ATTR_ADDRESS): cv.string,
|
||||||
vol.Required(ATTR_INTERFACE): cv.string,
|
vol.Required(ATTR_INTERFACE): cv.string,
|
||||||
|
vol.Optional(ATTR_DEVICE_TYPE): cv.string,
|
||||||
vol.Optional(ATTR_CHANNEL, default=DEFAULT_CHANNEL): vol.Coerce(int),
|
vol.Optional(ATTR_CHANNEL, default=DEFAULT_CHANNEL): vol.Coerce(int),
|
||||||
vol.Optional(ATTR_PARAM): cv.string,
|
vol.Optional(ATTR_PARAM): cv.string,
|
||||||
vol.Optional(ATTR_UNIQUE_ID): cv.string,
|
vol.Optional(ATTR_UNIQUE_ID): cv.string,
|
||||||
@ -533,6 +535,7 @@ def _get_devices(hass, discovery_type, keys, interface):
|
|||||||
ATTR_ADDRESS: key,
|
ATTR_ADDRESS: key,
|
||||||
ATTR_INTERFACE: interface,
|
ATTR_INTERFACE: interface,
|
||||||
ATTR_NAME: name,
|
ATTR_NAME: name,
|
||||||
|
ATTR_DEVICE_TYPE: class_name,
|
||||||
ATTR_CHANNEL: channel,
|
ATTR_CHANNEL: channel,
|
||||||
ATTR_UNIQUE_ID: unique_id,
|
ATTR_UNIQUE_ID: unique_id,
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ ATTR_DISCOVER_DEVICES = "devices"
|
|||||||
ATTR_PARAM = "param"
|
ATTR_PARAM = "param"
|
||||||
ATTR_CHANNEL = "channel"
|
ATTR_CHANNEL = "channel"
|
||||||
ATTR_ADDRESS = "address"
|
ATTR_ADDRESS = "address"
|
||||||
|
ATTR_DEVICE_TYPE = "device_type"
|
||||||
ATTR_VALUE = "value"
|
ATTR_VALUE = "value"
|
||||||
ATTR_VALUE_TYPE = "value_type"
|
ATTR_VALUE_TYPE = "value_type"
|
||||||
ATTR_INTERFACE = "interface"
|
ATTR_INTERFACE = "interface"
|
||||||
@ -151,7 +152,7 @@ HM_DEVICE_TYPES = {
|
|||||||
"IPRemoteMotionV2",
|
"IPRemoteMotionV2",
|
||||||
"IPWInputDevice",
|
"IPWInputDevice",
|
||||||
],
|
],
|
||||||
DISCOVER_COVER: ["Blind", "KeyBlind", "IPKeyBlind", "IPKeyBlindTilt"],
|
DISCOVER_COVER: ["Blind", "KeyBlind", "IPKeyBlind", "IPKeyBlindTilt", "IPGarage"],
|
||||||
DISCOVER_LOCKS: ["KeyMatic"],
|
DISCOVER_LOCKS: ["KeyMatic"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,14 +4,17 @@ import logging
|
|||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
ATTR_TILT_POSITION,
|
ATTR_TILT_POSITION,
|
||||||
|
DEVICE_CLASS_GARAGE,
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import ATTR_DISCOVER_DEVICES
|
from .const import ATTR_DEVICE_TYPE, ATTR_DISCOVER_DEVICES
|
||||||
from .entity import HMDevice
|
from .entity import HMDevice
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
HM_GARAGE = ("IPGarage",)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the platform."""
|
"""Set up the platform."""
|
||||||
@ -20,6 +23,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
|
|
||||||
devices = []
|
devices = []
|
||||||
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
|
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
|
if conf[ATTR_DEVICE_TYPE] in HM_GARAGE:
|
||||||
|
new_device = HMGarage(conf)
|
||||||
|
else:
|
||||||
new_device = HMCover(conf)
|
new_device = HMCover(conf)
|
||||||
devices.append(new_device)
|
devices.append(new_device)
|
||||||
|
|
||||||
@ -48,7 +54,7 @@ class HMCover(HMDevice, CoverEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_closed(self):
|
def is_closed(self):
|
||||||
"""Return if the cover is closed."""
|
"""Return whether the cover is closed."""
|
||||||
if self.current_cover_position is not None:
|
if self.current_cover_position is not None:
|
||||||
return self.current_cover_position == 0
|
return self.current_cover_position == 0
|
||||||
return None
|
return None
|
||||||
@ -105,3 +111,32 @@ class HMCover(HMDevice, CoverEntity):
|
|||||||
"""Stop cover tilt."""
|
"""Stop cover tilt."""
|
||||||
if "LEVEL_2" in self._data:
|
if "LEVEL_2" in self._data:
|
||||||
self.stop_cover(**kwargs)
|
self.stop_cover(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class HMGarage(HMCover):
|
||||||
|
"""Represents a Homematic Garage cover. Homematic garage covers do not support position attributes."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_cover_position(self):
|
||||||
|
"""
|
||||||
|
Return current position of cover.
|
||||||
|
|
||||||
|
None is unknown, 0 is closed, 100 is fully open.
|
||||||
|
"""
|
||||||
|
# Garage covers do not support position; always return None
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_closed(self):
|
||||||
|
"""Return whether the cover is closed."""
|
||||||
|
return self._hmdevice.is_closed(self._hm_get_state())
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the device class."""
|
||||||
|
return DEVICE_CLASS_GARAGE
|
||||||
|
|
||||||
|
def _init_data_struct(self):
|
||||||
|
"""Generate a data dictionary (self._data) from metadata."""
|
||||||
|
self._state = "DOOR_STATE"
|
||||||
|
self._data.update({self._state: None})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user