Change Insteon backend module to pyinsteon from insteonplm (#35198)
* Migrate to pyinsteon from insteonplm * Rename devices entities * Print ALDB even if not loaded * Add relay to name map * Change insteonplm to pyinsteon * Update requirements_all correctly * Code review updates * async_set_speed receive std speed value * default speed to std medium value * Call async methods for fan on/off * Comment await required in loop * Remove emtpy and add codeowner * Make services async and remove async_add_job call * Remove extra logging * New device as async task and aldb load in loop * Place lock in context bloxk * Limiting lock to min * Remove .env file
This commit is contained in:
1 parent
47801e7350
commit
dbd821a564
15 files changed
+617
-514
No files matched your search
@@ -1,50 +1,69 @@
|
||||
"""Support for INSTEON dimmers via PowerLinc Modem."""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
from pyinsteon.groups import (
|
||||
CO_SENSOR,
|
||||
DOOR_SENSOR,
|
||||
HEARTBEAT,
|
||||
LEAK_SENSOR_WET,
|
||||
LIGHT_SENSOR,
|
||||
LOW_BATTERY,
|
||||
MOTION_SENSOR,
|
||||
OPEN_CLOSE_SENSOR,
|
||||
SENSOR_MALFUNCTION,
|
||||
SMOKE_SENSOR,
|
||||
TEST_SENSOR,
|
||||
)
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_DOOR,
|
||||
DEVICE_CLASS_GAS,
|
||||
DEVICE_CLASS_LIGHT,
|
||||
DEVICE_CLASS_MOISTURE,
|
||||
DEVICE_CLASS_MOTION,
|
||||
DEVICE_CLASS_OPENING,
|
||||
DEVICE_CLASS_PROBLEM,
|
||||
DEVICE_CLASS_SAFETY,
|
||||
DEVICE_CLASS_SMOKE,
|
||||
DOMAIN,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
|
||||
from .insteon_entity import InsteonEntity
|
||||
from .utils import async_add_insteon_entities
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SENSOR_TYPES = {
|
||||
"openClosedSensor": "opening",
|
||||
"ioLincSensor": "opening",
|
||||
"motionSensor": "motion",
|
||||
"doorSensor": "door",
|
||||
"wetLeakSensor": "moisture",
|
||||
"lightSensor": "light",
|
||||
"batterySensor": "battery",
|
||||
OPEN_CLOSE_SENSOR: DEVICE_CLASS_OPENING,
|
||||
MOTION_SENSOR: DEVICE_CLASS_MOTION,
|
||||
DOOR_SENSOR: DEVICE_CLASS_DOOR,
|
||||
LEAK_SENSOR_WET: DEVICE_CLASS_MOISTURE,
|
||||
LIGHT_SENSOR: DEVICE_CLASS_LIGHT,
|
||||
LOW_BATTERY: DEVICE_CLASS_BATTERY,
|
||||
CO_SENSOR: DEVICE_CLASS_GAS,
|
||||
SMOKE_SENSOR: DEVICE_CLASS_SMOKE,
|
||||
TEST_SENSOR: DEVICE_CLASS_SAFETY,
|
||||
SENSOR_MALFUNCTION: DEVICE_CLASS_PROBLEM,
|
||||
HEARTBEAT: DEVICE_CLASS_PROBLEM,
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the INSTEON device class for the hass platform."""
|
||||
insteon_modem = hass.data["insteon"].get("modem")
|
||||
|
||||
address = discovery_info["address"]
|
||||
device = insteon_modem.devices[address]
|
||||
state_key = discovery_info["state_key"]
|
||||
name = device.states[state_key].name
|
||||
if name != "dryLeakSensor":
|
||||
_LOGGER.debug(
|
||||
"Adding device %s entity %s to Binary Sensor platform",
|
||||
device.address.hex,
|
||||
name,
|
||||
)
|
||||
|
||||
new_entity = InsteonBinarySensor(device, state_key)
|
||||
|
||||
async_add_entities([new_entity])
|
||||
"""Set up the INSTEON entity class for the hass platform."""
|
||||
async_add_insteon_entities(
|
||||
hass, DOMAIN, InsteonBinarySensorEntity, async_add_entities, discovery_info
|
||||
)
|
||||
|
||||
|
||||
class InsteonBinarySensor(InsteonEntity, BinarySensorEntity):
|
||||
"""A Class for an Insteon device entity."""
|
||||
class InsteonBinarySensorEntity(InsteonEntity, BinarySensorEntity):
|
||||
"""A Class for an Insteon binary sensor entity."""
|
||||
|
||||
def __init__(self, device, state_key):
|
||||
def __init__(self, device, group):
|
||||
"""Initialize the INSTEON binary sensor."""
|
||||
super().__init__(device, state_key)
|
||||
self._sensor_type = SENSOR_TYPES.get(self._insteon_device_state.name)
|
||||
super().__init__(device, group)
|
||||
self._sensor_type = SENSOR_TYPES.get(self._insteon_device_group.name)
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
@@ -54,9 +73,4 @@ class InsteonBinarySensor(InsteonEntity, BinarySensorEntity):
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return the boolean response if the node is on."""
|
||||
on_val = bool(self._insteon_device_state.value)
|
||||
|
||||
if self._insteon_device_state.name in ["lightSensor", "ioLincSensor"]:
|
||||
return not on_val
|
||||
|
||||
return on_val
|
||||
return bool(self._insteon_device_group.value)
|
||||
Reference in new issue
Block a user