mirror of
https://github.com/thecode/ha-rpi_gpio.git
synced 2025-07-28 21:26:42 +00:00
Skip failed entities instead of stop loading all of them (#356)
change async_setup_platform to just skip entities with HW issues instead of throwing and skipping the rest of the entities.
This commit is contained in:
parent
003993a3e5
commit
89eb52ee56
@ -52,17 +52,20 @@ async def async_setup_platform(
|
|||||||
|
|
||||||
sensors = []
|
sensors = []
|
||||||
for sensor in config.get(CONF_SENSORS):
|
for sensor in config.get(CONF_SENSORS):
|
||||||
sensors.append(
|
try:
|
||||||
GPIODBinarySensor(
|
sensors.append(
|
||||||
hub,
|
GPIODBinarySensor(
|
||||||
sensor[CONF_NAME],
|
hub,
|
||||||
sensor[CONF_PORT],
|
sensor[CONF_NAME],
|
||||||
sensor.get(CONF_UNIQUE_ID) or f"{DOMAIN}_{sensor[CONF_PORT]}_{sensor[CONF_NAME].lower().replace(' ', '_')}",
|
sensor[CONF_PORT],
|
||||||
sensor.get(CONF_INVERT_LOGIC),
|
sensor.get(CONF_UNIQUE_ID) or f"{DOMAIN}_{sensor[CONF_PORT]}_{sensor[CONF_NAME].lower().replace(' ', '_')}",
|
||||||
sensor.get(CONF_PULL_MODE),
|
sensor.get(CONF_INVERT_LOGIC),
|
||||||
sensor.get(CONF_BOUNCETIME)
|
sensor.get(CONF_PULL_MODE),
|
||||||
|
sensor.get(CONF_BOUNCETIME)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
except Exception as e:
|
||||||
|
_LOGGER.error(f"Failed to add binary sensor {sensor[CONF_NAME]} for port {sensor[CONF_PORT]}: {e}")
|
||||||
|
|
||||||
async_add_entities(sensors)
|
async_add_entities(sensors)
|
||||||
|
|
||||||
|
@ -71,21 +71,24 @@ async def async_setup_platform(
|
|||||||
invert_relay = config[CONF_INVERT_RELAY]
|
invert_relay = config[CONF_INVERT_RELAY]
|
||||||
covers = []
|
covers = []
|
||||||
for cover in config.get(CONF_COVERS):
|
for cover in config.get(CONF_COVERS):
|
||||||
covers.append(
|
try:
|
||||||
GPIODCover(
|
covers.append(
|
||||||
hub,
|
GPIODCover(
|
||||||
cover[CONF_NAME],
|
hub,
|
||||||
cover.get(CONF_RELAY_PIN),
|
cover[CONF_NAME],
|
||||||
relay_time,
|
cover.get(CONF_RELAY_PIN),
|
||||||
invert_relay,
|
relay_time,
|
||||||
"AS_IS",
|
invert_relay,
|
||||||
"PUSH_PULL",
|
"AS_IS",
|
||||||
cover.get(CONF_STATE_PIN),
|
"PUSH_PULL",
|
||||||
state_pull_mode,
|
cover.get(CONF_STATE_PIN),
|
||||||
invert_state,
|
state_pull_mode,
|
||||||
cover.get(CONF_UNIQUE_ID) or f"{DOMAIN}_{cover.get(CONF_RELAY_PIN)}_{cover[CONF_NAME].lower().replace(' ', '_')}",
|
invert_state,
|
||||||
|
cover.get(CONF_UNIQUE_ID) or f"{DOMAIN}_{cover.get(CONF_RELAY_PIN)}_{cover[CONF_NAME].lower().replace(' ', '_')}",
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
except Exception as e:
|
||||||
|
_LOGGER.error(f"Failed to add cover {cover[CONF_NAME]} for port {cover.get(CONF_RELAY_PIN)}:{cover.get(CONF_STATE_PIN)}: {e}")
|
||||||
|
|
||||||
async_add_entities(covers)
|
async_add_entities(covers)
|
||||||
|
|
||||||
|
@ -56,18 +56,21 @@ async def async_setup_platform(
|
|||||||
|
|
||||||
switches = []
|
switches = []
|
||||||
for switch in config.get(CONF_SWITCHES):
|
for switch in config.get(CONF_SWITCHES):
|
||||||
switches.append(
|
try:
|
||||||
GPIODSwitch(
|
switches.append(
|
||||||
hub,
|
GPIODSwitch(
|
||||||
switch[CONF_NAME],
|
hub,
|
||||||
switch[CONF_PORT],
|
switch[CONF_NAME],
|
||||||
switch.get(CONF_UNIQUE_ID) or f"{DOMAIN}_{switch[CONF_PORT]}_{switch[CONF_NAME].lower().replace(' ', '_')}",
|
switch[CONF_PORT],
|
||||||
switch.get(CONF_INVERT_LOGIC),
|
switch.get(CONF_UNIQUE_ID) or f"{DOMAIN}_{switch[CONF_PORT]}_{switch[CONF_NAME].lower().replace(' ', '_')}",
|
||||||
switch.get(CONF_PULL_MODE),
|
switch.get(CONF_INVERT_LOGIC),
|
||||||
switch.get(CONF_DRIVE),
|
switch.get(CONF_PULL_MODE),
|
||||||
switch[CONF_PERSISTENT]
|
switch.get(CONF_DRIVE),
|
||||||
|
switch[CONF_PERSISTENT]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
except Exception as e:
|
||||||
|
_LOGGER.error(f"Failed to add switch {switch[CONF_NAME]} for port {switch[CONF_PORT]}: {e}")
|
||||||
|
|
||||||
async_add_entities(switches)
|
async_add_entities(switches)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user