Skip to content

Commit

Permalink
- Fix "RuntimeError: Detected that custom integration ..."
Browse files Browse the repository at this point in the history
- Immediately update sensors when starting, instead of waiting 5 minutes.
  • Loading branch information
Breina committed May 2, 2024
1 parent e068436 commit 466e442
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion custom_components/idrac_power/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ def name(self):

def update_value(self, status: bool):
self._attr_is_on = status
self.async_schedule_update_ha_state()
self.schedule_update_ha_state()
17 changes: 11 additions & 6 deletions custom_components/idrac_power/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e
async def refresh_sensors_task():
while True:
_LOGGER.debug("Refreshing sensors")
await hass.async_add_executor_job(rest_client.update_thermals)
await hass.async_add_executor_job(rest_client.update_status)
await hass.async_add_executor_job(rest_client.update_power_usage)
await update_all()
await asyncio.sleep(rest_client.interval)

async def update_all():
await hass.async_add_executor_job(rest_client.update_thermals)
await hass.async_add_executor_job(rest_client.update_status)
await hass.async_add_executor_job(rest_client.update_power_usage)

await update_all()

hass.async_create_background_task(refresh_sensors_task(), f"Update {name} iDRAC task")


Expand Down Expand Up @@ -100,7 +105,7 @@ def __init__(self, hass, rest: IdracRest, device_info, unique_id, name):

def update_value(self, new_value: int):
self._attr_native_value = new_value
self.async_schedule_update_ha_state()
self.schedule_update_ha_state()


class IdracFanSensor(SensorEntity):
Expand All @@ -127,7 +132,7 @@ def __init__(self, hass, rest: IdracRest, device_info, unique_id, name, index):

def update_value(self, thermal: dict):
self._attr_native_value = thermal['Fans'][self.index]['Reading']
self.async_schedule_update_ha_state()
self.schedule_update_ha_state()


class IdracTempSensor(SensorEntity):
Expand All @@ -154,4 +159,4 @@ def __init__(self, hass, rest: IdracRest, device_info, unique_id, name, index):

def update_value(self, thermal: dict):
self._attr_native_value = thermal['Temperatures'][self.index]['ReadingCelsius']
self.async_schedule_update_ha_state()
self.schedule_update_ha_state()

0 comments on commit 466e442

Please sign in to comment.