Skip to content

Commit

Permalink
Merge branch 'master' into process-outgoing-telegrams
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-w committed Sep 21, 2020
2 parents bdd9dad + 1e63b8d commit 4ea55be
Show file tree
Hide file tree
Showing 34 changed files with 449 additions and 422 deletions.
35 changes: 34 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
# Changelog

## Upcoming version (unreleased)
## 0.14.3 Bugfix release

### Internals

- Make connectivity less noisy on connection errors.

## 0.14.2 Bugfix release

### Bugfixes

- Correctly reset the counter of the binary sensor after a trigger.

## 0.14.1 Bugfix release

### Bugfixes

- Use correct DPT 9.006 for the air pressure attribute of weather devices
- Reset binary sensor counters after the context has been timed out in order to be able to use state change events within HA
- Code cleanups

## 0.14.0 New sensor types and refacoring of binary sensor automations

### Breaking changes

- Binary sensor automations within the home assistant integration have been refactored to use the HA built in events as automation source instead of having the automation schema directly attached to the sensors. (Migration Guide: https://xknx.io/migration_ha_0116.html)

### New Features

- Add support for new sensor types DPT 12.1200 (DPT_VolumeLiquid_Litre) and DPT 12.1201 (DPTVolumeM3).
- Weather devices now have an additional `brightness_north` GA to measure the brightness. Additionally, all sensor values are now part of the HA device state attributes for a given weather device.

### Bugfixes

- Fix hourly broadcasting of localtime

### Internals

Expand Down
34 changes: 22 additions & 12 deletions docs/migration_ha_0116.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,32 @@ and your new automation will look like this:
```yaml

automation:
- trigger:
- platform: event
event_type: knx_binary_sensor.cover_abstell
event_data:
counter: 1
state: "on"
- alias: 'Binary sensor test counter=1 on'
trigger:
platform: numeric_state
entity_id: binary_sensor.cover_abstell
attribute: counter
above: 0
below: 2
condition:
- condition: state
entity_id: binary_sensor.cover_abstell
state: 'on'
action:
- service: cover.open_cover
entity_id: cover.sonne_abstellkammer

- trigger:
- platform: event
event_type: knx_binary_sensor.cover_abstell
event_data:
counter: 1
state: "off"
- alias: 'Binary sensor test counter=1 off'
trigger:
platform: numeric_state
entity_id: binary_sensor.cover_abstell
attribute: counter
above: 0
below: 2
condition:
- condition: state
entity_id: binary_sensor.cover_abstell
state: 'off'
action:
- service: cover.close_cover
entity_id: cover.sonne_abstellkammer
Expand Down
18 changes: 12 additions & 6 deletions home-assistant-plugin/custom_components/xknx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import async_track_state_change_event

from .const import DATA_XKNX, DOMAIN, SupportedPlatforms
from .const import DOMAIN, SupportedPlatforms
from .factory import create_knx_device
from .schema import (
BinarySensorSchema,
Expand Down Expand Up @@ -139,9 +139,9 @@
async def async_setup(hass, config):
"""Set up the KNX component."""
try:
hass.data[DATA_XKNX] = KNXModule(hass, config)
hass.data[DATA_XKNX].async_create_exposures()
await hass.data[DATA_XKNX].start()
hass.data[DOMAIN] = KNXModule(hass, config)
hass.data[DOMAIN].async_create_exposures()
await hass.data[DOMAIN].start()
except XKNXException as ex:
_LOGGER.warning("Could not connect to KNX interface: %s", ex)
hass.components.persistent_notification.async_create(
Expand All @@ -151,18 +151,24 @@ async def async_setup(hass, config):
for platform in SupportedPlatforms:
if platform.value in config[DOMAIN]:
for device_config in config[DOMAIN][platform.value]:
create_knx_device(platform, hass.data[DATA_XKNX].xknx, device_config)
create_knx_device(platform, hass.data[DOMAIN].xknx, device_config)

# We need to wait until all entities are loaded into the device list since they could also be created from other platforms
for platform in SupportedPlatforms:
hass.async_create_task(
discovery.async_load_platform(hass, platform.value, DOMAIN, {}, config)
)

if not hass.data[DOMAIN].xknx.devices:
_LOGGER.warning(
"No KNX devices are configured. Please read "
"https://www.home-assistant.io/blog/2020/09/17/release-115/#breaking-changes"
)

hass.services.async_register(
DOMAIN,
SERVICE_XKNX_SEND,
hass.data[DATA_XKNX].service_send_to_knx_bus,
hass.data[DOMAIN].service_send_to_knx_bus,
schema=SERVICE_XKNX_SEND_SCHEMA,
)

Expand Down
68 changes: 16 additions & 52 deletions home-assistant-plugin/custom_components/xknx/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,79 +1,43 @@
"""Support for KNX/IP binary sensors."""
import asyncio
from typing import Any, Dict, Optional

from xknx.devices import BinarySensor as XknxBinarySensor

from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import callback
from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorEntity

from .const import DATA_XKNX, DOMAIN
from .const import ATTR_COUNTER, DOMAIN
from .knx_entity import KnxEntity


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up binary sensor(s) for KNX platform."""
entities = []
for device in hass.data[DATA_XKNX].xknx.devices:
for device in hass.data[DOMAIN].xknx.devices:
if isinstance(device, XknxBinarySensor):
entities.append(KNXBinarySensor(device))
async_add_entities(entities)


class KNXBinarySensor(BinarySensorEntity):
class KNXBinarySensor(KnxEntity, BinarySensorEntity):
"""Representation of a KNX binary sensor."""

def __init__(self, device: XknxBinarySensor):
"""Initialize of KNX binary sensor."""
self.device = device

@callback
def async_register_callbacks(self):
"""Register callbacks to update hass after device was changed."""

async def after_update_callback(device: XknxBinarySensor):
"""Call after device was updated."""
self.async_write_ha_state()

self.hass.bus.fire(
f"{DOMAIN}_{self.entity_id}",
{
# how often has the input sensor been pressed
"counter": device.counter,
"state": STATE_ON if device.state else STATE_OFF,
},
)

self.device.register_device_updated_cb(after_update_callback)

async def async_added_to_hass(self):
"""Store register state change callback."""
self.async_register_callbacks()

async def async_update(self):
"""Request a state update from KNX bus."""
await self.device.sync()

@property
def name(self):
"""Return the name of the KNX device."""
return self.device.name

@property
def available(self):
"""Return True if entity is available."""
return self.hass.data[DATA_XKNX].connected

@property
def should_poll(self):
"""No polling needed within KNX."""
return False
super().__init__(device)

@property
def device_class(self):
"""Return the class of this sensor."""
return self.device.device_class
if self._device.device_class in DEVICE_CLASSES:
return self._device.device_class
return None

@property
def is_on(self):
"""Return true if the binary sensor is on."""
return self.device.is_on()
return self._device.is_on()

@property
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
"""Return device specific state attributes."""
return {ATTR_COUNTER: self._device.counter}

0 comments on commit 4ea55be

Please sign in to comment.