Fix for battery device: new_device referenced before assignment. (#23793)
* Fix for battery device: new_device referenced before assignment. * Fix buttons and switches mixup * Update __init__.py * Update binary_sensor.py * Update __init__.py * Update __init__.py * Update binary_sensor.py * Update __init__.py * Update binary_sensor.py * typo and indentation fixes * low_bat and lowbat to uppercase.
This commit is contained in:
1 parent
990a9e80a2
commit
b2a1204bc5
2 files changed
+30
-40
No files matched your search
@@ -2,16 +2,14 @@
|
||||
import logging
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
from homeassistant.components.homematic import ATTR_BATTERY_DEVICES
|
||||
from homeassistant.const import STATE_UNKNOWN, DEVICE_CLASS_BATTERY
|
||||
from homeassistant.components.homematic import (
|
||||
ATTR_DISCOVERY_TYPE, DISCOVER_BATTERY)
|
||||
from homeassistant.const import DEVICE_CLASS_BATTERY
|
||||
|
||||
from . import ATTR_DISCOVER_DEVICES, HMDevice
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_LOW_BAT = 'LOW_BAT'
|
||||
ATTR_LOWBAT = 'LOWBAT'
|
||||
|
||||
SENSOR_TYPES_CLASS = {
|
||||
'IPShutterContact': 'opening',
|
||||
'MaxShutterContact': 'opening',
|
||||
@@ -34,16 +32,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
return
|
||||
|
||||
devices = []
|
||||
battery_devices = discovery_info[ATTR_BATTERY_DEVICES]
|
||||
|
||||
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||
if battery_devices:
|
||||
battery_device = conf.get(ATTR_LOWBAT) or conf.get(ATTR_LOW_BAT)
|
||||
if battery_device:
|
||||
new_device = HMBatterySensor(conf)
|
||||
if discovery_info[ATTR_DISCOVERY_TYPE] == DISCOVER_BATTERY:
|
||||
devices.append(HMBatterySensor(conf))
|
||||
else:
|
||||
new_device = HMBinarySensor(conf)
|
||||
devices.append(new_device)
|
||||
devices.append(HMBinarySensor(conf))
|
||||
|
||||
add_entities(devices)
|
||||
|
||||
@@ -70,7 +63,7 @@ class HMBinarySensor(HMDevice, BinarySensorDevice):
|
||||
"""Generate the data dictionary (self._data) from metadata."""
|
||||
# Add state to data struct
|
||||
if self._state:
|
||||
self._data.update({self._state: STATE_UNKNOWN})
|
||||
self._data.update({self._state: None})
|
||||
|
||||
|
||||
class HMBatterySensor(HMDevice, BinarySensorDevice):
|
||||
@@ -84,13 +77,10 @@ class HMBatterySensor(HMDevice, BinarySensorDevice):
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return True if battery is low."""
|
||||
is_on = self._data.get(ATTR_LOW_BAT, False) or self._data.get(
|
||||
ATTR_LOWBAT, False
|
||||
)
|
||||
return is_on
|
||||
return bool(self._hm_get_state())
|
||||
|
||||
def _init_data_struct(self):
|
||||
"""Generate the data dictionary (self._data) from metadata."""
|
||||
# Add state to data struct
|
||||
if self._state:
|
||||
self._data.update({self._state: STATE_UNKNOWN})
|
||||
self._data.update({self._state: None})
|
||||
Reference in new issue
Block a user