|
1 | 1 | """Camera-related services for the MQTT Vacuum Camera integration."""
|
2 | 2 |
|
| 3 | +import logging |
3 | 4 | import asyncio
|
4 | 5 | import async_timeout
|
5 |
| -import logging |
6 |
| - |
7 | 6 |
|
8 | 7 | from homeassistant.core import ServiceCall, HomeAssistant
|
9 | 8 | from homeassistant.config_entries import ConfigEntryState
|
10 | 9 | from homeassistant.const import SERVICE_RELOAD
|
11 | 10 |
|
12 | 11 | from ...utils.files_operations import async_clean_up_all_auto_crop_files
|
| 12 | +from ...const import DOMAIN |
13 | 13 |
|
14 | 14 | _LOGGER = logging.getLogger(__name__)
|
15 | 15 |
|
16 |
| -async def reset_trims(hass: HomeAssistant, call: ServiceCall, domain: str) -> None: |
| 16 | + |
| 17 | +async def reset_trims(call: ServiceCall, hass: HomeAssistant) -> None: |
17 | 18 | """Action Reset Map Trims."""
|
18 |
| - _LOGGER.debug(f"Resetting trims for {domain}") |
| 19 | + _LOGGER.debug(f"Resetting trims for {DOMAIN}") |
19 | 20 | try:
|
20 | 21 | await async_clean_up_all_auto_crop_files(hass)
|
21 |
| - await hass.services.async_call(domain, SERVICE_RELOAD) |
22 |
| - hass.bus.async_fire(f"event_{domain}_reset_trims", context=call.context) |
| 22 | + await hass.services.async_call(DOMAIN, SERVICE_RELOAD) |
| 23 | + hass.bus.async_fire(f"event_{DOMAIN}_reset_trims", context=call.context) |
23 | 24 | except Exception as err:
|
24 | 25 | _LOGGER.error(f"Error resetting trims: {err}")
|
25 | 26 |
|
26 | 27 |
|
27 |
| -async def reload_config(hass: HomeAssistant, domain: str) -> None: |
| 28 | +async def reload_camera_config(call: ServiceCall, hass: HomeAssistant) -> None: |
28 | 29 | """Reload the camera platform for all entities in the integration."""
|
29 |
| - _LOGGER.debug(f"Reloading the config entry for all {domain} entities") |
30 |
| - camera_entries = hass.config_entries.async_entries(domain) |
| 30 | + |
| 31 | + _LOGGER.debug(f"Reloading the config entry for all {DOMAIN} entities") |
| 32 | + camera_entries = hass.config_entries.async_entries(DOMAIN) |
31 | 33 | total_entries = len(camera_entries)
|
32 | 34 | processed = 0
|
33 | 35 |
|
34 | 36 | for camera_entry in camera_entries:
|
35 | 37 | processed += 1
|
36 | 38 | _LOGGER.info(f"Processing entry {processed}/{total_entries}")
|
37 | 39 | if camera_entry.state == ConfigEntryState.LOADED:
|
38 |
| - _LOGGER.debug(f"Unloading entry: {camera_entry.entry_id}") |
39 | 40 | try:
|
40 |
| - async with async_timeout.timeout(30): |
41 |
| - await hass.config_entries.async_unload(camera_entry.entry_id) |
42 |
| - |
43 |
| - _LOGGER.debug(f"Reloading entry: {camera_entry.entry_id}") |
44 |
| - await hass.config_entries.async_setup(camera_entry.entry_id) |
| 41 | + with async_timeout.timeout(10): |
| 42 | + _LOGGER.debug(f"Reloading entry: {camera_entry.entry_id}") |
| 43 | + hass.config_entries.async_schedule_reload(camera_entry.entry_id) |
45 | 44 | except asyncio.TimeoutError:
|
46 |
| - _LOGGER.error(f"Timeout while processing entry {camera_entry.entry_id}") |
47 |
| - continue |
| 45 | + _LOGGER.error(f"Timeout processing entry {camera_entry.entry_id}") |
48 | 46 | except Exception as err:
|
49 | 47 | _LOGGER.error(f"Error processing entry {camera_entry.entry_id}: {err}")
|
50 | 48 | continue
|
51 | 49 | else:
|
52 |
| - _LOGGER.debug( |
53 |
| - f"Skipping entry {camera_entry.entry_id} as it is NOT_LOADED" |
54 |
| - ) |
55 |
| - |
56 |
| - hass.bus.async_fire(f"event_{domain}_reloaded", { |
57 |
| - "processed": processed, |
58 |
| - "total": total_entries |
59 |
| - }) |
| 50 | + _LOGGER.debug(f"Skipping entry {camera_entry.entry_id} as it is NOT_LOADED") |
| 51 | + |
| 52 | + hass.bus.async_fire( |
| 53 | + f"event_{DOMAIN}_reloaded", |
| 54 | + event_data={ |
| 55 | + "processed": processed, |
| 56 | + "total": total_entries, |
| 57 | + }, |
| 58 | + context=call.context, |
| 59 | + ) |
0 commit comments