diff --git a/custom_components/bluetti_bt/binary_sensor.py b/custom_components/bluetti_bt/binary_sensor.py index 67cfe38..ecf00d9 100644 --- a/custom_components/bluetti_bt/binary_sensor.py +++ b/custom_components/bluetti_bt/binary_sensor.py @@ -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, ) diff --git a/custom_components/bluetti_bt/config_flow.py b/custom_components/bluetti_bt/config_flow.py index 6dcb071..025f2ef 100644 --- a/custom_components/bluetti_bt/config_flow.py +++ b/custom_components/bluetti_bt/config_flow.py @@ -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={ diff --git a/custom_components/bluetti_bt/sensor.py b/custom_components/bluetti_bt/sensor.py index 66ca581..1347396 100644 --- a/custom_components/bluetti_bt/sensor.py +++ b/custom_components/bluetti_bt/sensor.py @@ -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 diff --git a/custom_components/bluetti_bt/switch.py b/custom_components/bluetti_bt/switch.py index 0d6a83e..2945226 100644 --- a/custom_components/bluetti_bt/switch.py +++ b/custom_components/bluetti_bt/switch.py @@ -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, ) diff --git a/custom_components/bluetti_bt/translations/de.json b/custom_components/bluetti_bt/translations/de.json index abe7a9e..b30d9f9 100644 --- a/custom_components/bluetti_bt/translations/de.json +++ b/custom_components/bluetti_bt/translations/de.json @@ -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" } } } \ No newline at end of file diff --git a/custom_components/bluetti_bt/translations/en.json b/custom_components/bluetti_bt/translations/en.json index 5aa6eb7..3d0e7e6 100644 --- a/custom_components/bluetti_bt/translations/en.json +++ b/custom_components/bluetti_bt/translations/en.json @@ -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" } } } \ No newline at end of file