Skip to content

Commit

Permalink
Add DEVICE_CLASS support for cover (#479)
Browse files Browse the repository at this point in the history
* Add DEVICE_CLASS support for cover

* Update cover.md

* Update cover.md

* Update cover.md

* Updates for DEVICE_CLASS support of covers

* Updates for DEVICE_CLASS support of covers

* Updates for DEVICE_CLASS support of covers

* Update docs/configuration.md

Co-authored-by: Marvin Wichmann <marvin@fam-wichmann.de>

* Updates for DEVICE_CLASS support of covers

* Updates for DEVICE_CLASS support of covers

Co-authored-by: Marvin Wichmann <marvin@fam-wichmann.de>
  • Loading branch information
KNXBroker and marvin-w committed Nov 2, 2020
1 parent c986478 commit d278eb1
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ groups:
travel_time_up: 60,
}

# Covers without direct positioning:
# Covers without direct positioning and device class "shutter":
Livingroom.Shutter_3:
{
group_address_long: "1/4/9",
group_address_short: "1/4/10",
group_address_position_feedback: "1/4/11",
travel_time_down: 50,
travel_time_up: 60,
device_class: "shutter",
}

# Central Shutters dont have short or position address
Expand Down
4 changes: 3 additions & 1 deletion docs/cover.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Shutters are simple representations of blind/roller cover actuators. With XKNX y
- `travel_time_up` seconds to reach upper end position. Default: 22
- `invert_position` invert position (payload for eg. set_up() and relative position). Default: False
- `invert_angle` invert angle. Default: False
- `device_class` may be used to store the type of cover, e.g. "shutter" for Home-Assistant (see [cover documentation](https://www.home-assistant.io/integrations/cover/) for details).
- `device_updated_cb` awaitable callback for each update.

## [](#header-2)Example
Expand All @@ -42,7 +43,8 @@ cover = Cover(xknx,
travel_time_down=50,
travel_time_up=60,
invert_position=False,
invert_angle=False)
invert_angle=False,
device_class='shutter')

# Moving to up position
await cover.set_up()
Expand Down
3 changes: 3 additions & 0 deletions home-assistant-plugin/custom_components/xknx/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ATTR_POSITION,
ATTR_TILT_POSITION,
DEVICE_CLASS_BLIND,
DEVICE_CLASSES,
SUPPORT_CLOSE,
SUPPORT_OPEN,
SUPPORT_SET_POSITION,
Expand Down Expand Up @@ -47,6 +48,8 @@ async def after_update_callback(self, device):
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
if self._device.device_class in DEVICE_CLASSES:
return self._device.device_class
if self._device.supports_angle:
return DEVICE_CLASS_BLIND
return None
Expand Down
1 change: 1 addition & 0 deletions home-assistant-plugin/custom_components/xknx/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def _create_cover(knx_module: XKNX, config: ConfigType) -> XknxCover:
travel_time_up=config[CoverSchema.CONF_TRAVELLING_TIME_UP],
invert_position=config[CoverSchema.CONF_INVERT_POSITION],
invert_angle=config[CoverSchema.CONF_INVERT_ANGLE],
device_class=config.get(CONF_DEVICE_CLASS),
)


Expand Down
1 change: 1 addition & 0 deletions home-assistant-plugin/custom_components/xknx/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CoverSchema:
): cv.positive_int,
vol.Optional(CONF_INVERT_POSITION, default=False): cv.boolean,
vol.Optional(CONF_INVERT_ANGLE, default=False): cv.boolean,
vol.Optional(CONF_DEVICE_CLASS): cv.string,
}
)

Expand Down
16 changes: 16 additions & 0 deletions test/config_tests/config_v1_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,22 @@ def test_config_cover(self):
),
)

def test_config_cover_device_class(self):
"""Test reading cover with device_class from config file."""
self.assertEqual(
TestConfig.xknx.devices["Livingroom.Shutter_3"],
Cover(
TestConfig.xknx,
"Livingroom.Shutter_3",
group_address_long="1/4/9",
group_address_short="1/4/10",
group_address_position_state="1/4/11",
travel_time_down=50,
travel_time_up=60,
device_class="shutter",
),
)

def test_config_cover_venetian(self):
"""Test reading Cover with angle from config file."""
self.assertEqual(
Expand Down
3 changes: 2 additions & 1 deletion xknx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ groups:
travel_time_up: 60,
}

# Covers without direct positioning:
# Covers without direct positioning and device class "shutter":
Livingroom.Shutter_3:
{
group_address_long: "1/4/9",
group_address_short: "1/4/10",
group_address_position_state: "1/4/11",
travel_time_down: 50,
travel_time_up: 60,
device_class: "shutter",
}

# Central Shutters dont have short or position address
Expand Down
5 changes: 5 additions & 0 deletions xknx/devices/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(
invert_position=False,
invert_angle=False,
device_updated_cb=None,
device_class=None,
):
"""Initialize Cover class."""
# pylint: disable=too-many-arguments
Expand Down Expand Up @@ -110,6 +111,8 @@ def __init__(

self.travelcalculator = TravelCalculator(travel_time_down, travel_time_up)

self.device_class = device_class

def _iter_remote_values(self):
"""Iterate the devices RemoteValue classes."""
yield from (self.updown, self.step, self.stop_, self.position, self.angle)
Expand All @@ -128,6 +131,7 @@ def from_config(cls, xknx, name, config):
travel_time_up = config.get("travel_time_up", cls.DEFAULT_TRAVEL_TIME_UP)
invert_position = config.get("invert_position", False)
invert_angle = config.get("invert_angle", False)
device_class = config.get("device_class")

return cls(
xknx,
Expand All @@ -143,6 +147,7 @@ def from_config(cls, xknx, name, config):
travel_time_up=travel_time_up,
invert_position=invert_position,
invert_angle=invert_angle,
device_class=device_class,
)

def __str__(self):
Expand Down

0 comments on commit d278eb1

Please sign in to comment.