added validation for polling interval
This commit is contained in:
1 parent
15216e1268
commit
a5ced35d32
6 files changed
+22
-11
No files matched your search
@@ -35,7 +35,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Setup sensor entities."""
|
||||
"""Setup binary_sensor entities."""
|
||||
|
||||
device_name = entry.data.get(CONF_NAME)
|
||||
address = entry.data.get(CONF_ADDRESS)
|
||||
@@ -43,7 +43,7 @@ async def async_setup_entry(
|
||||
_LOGGER.error("Device has no address")
|
||||
|
||||
# Generate device info
|
||||
_LOGGER.info("Creating sensors for device with address %s", address)
|
||||
_LOGGER.info("Creating binary_sensors for device with address %s", address)
|
||||
device_info = dev_info(entry)
|
||||
|
||||
# Add sensors according to device_info
|
||||
@@ -105,8 +105,8 @@ class BluettiBinarySensor(CoordinatorEntity, BinarySensorEntity):
|
||||
"""Handle updated data from the coordinator."""
|
||||
_LOGGER.debug("Updating state of %s", self._attr_unique_id)
|
||||
if not isinstance(self.coordinator.data, dict):
|
||||
_LOGGER.error(
|
||||
"Invalid data from coordinator (sensor.%s)", self._attr_unique_id
|
||||
_LOGGER.debug(
|
||||
"Invalid data from coordinator (binary_sensor.%s)", self._attr_unique_id
|
||||
)
|
||||
self._attr_available = False
|
||||
return
|
||||
@@ -118,7 +118,7 @@ class BluettiBinarySensor(CoordinatorEntity, BinarySensorEntity):
|
||||
|
||||
if not isinstance(response_data, bool):
|
||||
_LOGGER.warning(
|
||||
"Invalid response data type from coordinator (sensor.%s): %s",
|
||||
"Invalid response data type from coordinator (binary_sensor.%s): %s",
|
||||
self._attr_unique_id,
|
||||
response_data,
|
||||
)
|
||||
|
||||
@@ -108,6 +108,11 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
||||
) -> FlowResult:
|
||||
"""Manage the options."""
|
||||
if user_input is not None:
|
||||
|
||||
# Validate update interval
|
||||
if user_input[CONF_POLLING_INTERVAL] < 5:
|
||||
return self.async_abort(reason="invalid_interval")
|
||||
|
||||
changed = self.hass.config_entries.async_update_entry(
|
||||
self.config_entry,
|
||||
data={
|
||||
|
||||
@@ -131,7 +131,7 @@ class BluettiSensor(CoordinatorEntity, SensorEntity):
|
||||
"""Handle updated data from the coordinator."""
|
||||
_LOGGER.debug("Updating state of %s", self._attr_unique_id)
|
||||
if not isinstance(self.coordinator.data, dict):
|
||||
_LOGGER.error(
|
||||
_LOGGER.debug(
|
||||
"Invalid data from coordinator (sensor.%s)", self._attr_unique_id
|
||||
)
|
||||
self._attr_available = False
|
||||
|
||||
@@ -50,7 +50,7 @@ async def async_setup_entry(
|
||||
_LOGGER.error("Device has no address")
|
||||
|
||||
# Generate device info
|
||||
_LOGGER.info("Creating sensors for device with address %s", address)
|
||||
_LOGGER.info("Creating switches for device with address %s", address)
|
||||
device_info = dev_info(entry)
|
||||
|
||||
# Add sensors according to device_info
|
||||
@@ -116,7 +116,7 @@ class BluettiSwitch(CoordinatorEntity, SwitchEntity):
|
||||
_LOGGER.debug("Updating state of %s", self._attr_unique_id)
|
||||
if not isinstance(self.coordinator.data, dict):
|
||||
_LOGGER.error(
|
||||
"Invalid data from coordinator (sensor.%s)", self._attr_unique_id
|
||||
"Invalid data from coordinator (switch.%s)", self._attr_unique_id
|
||||
)
|
||||
self._attr_available = False
|
||||
return
|
||||
@@ -128,7 +128,7 @@ class BluettiSwitch(CoordinatorEntity, SwitchEntity):
|
||||
|
||||
if not isinstance(response_data, bool):
|
||||
_LOGGER.warning(
|
||||
"Invalid response data type from coordinator (sensor.%s): %s",
|
||||
"Invalid response data type from coordinator (switch.%s): %s",
|
||||
self._attr_unique_id,
|
||||
response_data,
|
||||
)
|
||||
|
||||
@@ -4,10 +4,13 @@
|
||||
"init": {
|
||||
"data": {
|
||||
"use_controls": "Steuerung aktivieren (auf eigenes Risiko)",
|
||||
"persistant_conn": "Dauerhafte Verbindung",
|
||||
"persistant_conn": "Dauerhafte Verbindung (Neustart erforderlich)",
|
||||
"polling_interval": "Datenabruf-Intervall in Sekunden (Neustart erforderlich)"
|
||||
}
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"invalid_interval": "Ungültiger Datenabruf-Intervall. Verwende 5 Sekunden oder mehr"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,13 @@
|
||||
"init": {
|
||||
"data": {
|
||||
"use_controls": "Use controls (use at own risk)",
|
||||
"persistant_conn": "Persistant connection",
|
||||
"persistant_conn": "Persistant connection (restart required)",
|
||||
"polling_interval": "Polling interval in seconds (restart required)"
|
||||
}
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"invalid_interval": "Invalid polling interval. Use 5 seconds or more"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user