-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring Services for the Camera and improving init
Signed-off-by: [email protected] <[email protected]>
- Loading branch information
Showing
3 changed files
with
63 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
custom_components/mqtt_vacuum_camera/utils/camera/camera_services.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Camera-related services for the MQTT Vacuum Camera integration.""" | ||
|
||
import logging | ||
|
||
|
||
from homeassistant.core import ServiceCall, HomeAssistant | ||
from homeassistant.config_entries import ConfigEntryState | ||
from homeassistant.const import SERVICE_RELOAD | ||
|
||
from ...utils.files_operations import async_clean_up_all_auto_crop_files | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
async def reset_trims(hass: HomeAssistant, call: ServiceCall, domain: str) -> None: | ||
"""Action Reset Map Trims.""" | ||
_LOGGER.debug(f"Resetting trims for {domain}") | ||
await async_clean_up_all_auto_crop_files(hass) | ||
await hass.services.async_call(domain, SERVICE_RELOAD) | ||
hass.bus.async_fire(f"event_{domain}_reset_trims", context=call.context) | ||
|
||
|
||
async def reload_config(hass: HomeAssistant, domain: str) -> None: | ||
"""Reload the camera platform for all entities in the integration.""" | ||
_LOGGER.debug(f"Reloading the config entry for all {domain} entities") | ||
camera_entries = hass.config_entries.async_entries(domain) | ||
|
||
for camera_entry in camera_entries: | ||
if camera_entry.state == ConfigEntryState.LOADED: | ||
_LOGGER.debug(f"Unloading entry: {camera_entry.entry_id}") | ||
await hass.config_entries.async_unload(camera_entry.entry_id) | ||
|
||
_LOGGER.debug(f"Reloading entry: {camera_entry.entry_id}") | ||
await hass.config_entries.async_setup(camera_entry.entry_id) | ||
else: | ||
_LOGGER.debug( | ||
f"Skipping entry {camera_entry.entry_id} as it is NOT_LOADED" | ||
) | ||
|
||
hass.bus.async_fire(f"event_{domain}_reloaded") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters