From f8f8c7927d88339bfc27b810b6c18cb9047ce616 Mon Sep 17 00:00:00 2001 From: sudoxnym <76703581+sudoxnym@users.noreply.github.com> Date: Mon, 14 Apr 2025 18:17:05 -0600 Subject: [PATCH] Add files via upload --- custom_components/saas/__init__.py | 24 ++++++------------------ custom_components/saas/button.py | 2 +- custom_components/saas/manifest.json | 1 - custom_components/saas/sensor.py | 1 - custom_components/saas/services.py | 6 ++---- 5 files changed, 9 insertions(+), 25 deletions(-) diff --git a/custom_components/saas/__init__.py b/custom_components/saas/__init__.py index 9ebcca0..28671be 100644 --- a/custom_components/saas/__init__.py +++ b/custom_components/saas/__init__.py @@ -2,23 +2,10 @@ import asyncio import logging from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant -from homeassistant.exceptions import ConfigEntryNotReady from .const import DOMAIN from homeassistant.helpers.dispatcher import async_dispatcher_connect from .services import async_setup_services # Import the service setup function -try: - import homeassistant - import logging - logging.getLogger(__name__).info("SAAS init loaded successfully") -except Exception as e: - import traceback - logging.getLogger(__name__).error(f"SAAS init failed: {e}\n{traceback.format_exc()}") - raise - - - - _logger = logging.getLogger(__name__) async def async_setup(hass: HomeAssistant, config: dict): @@ -29,11 +16,6 @@ async def async_setup(hass: HomeAssistant, config: dict): async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up a config entry.""" _logger.info(f"Starting setup of config entry with ID: {entry.entry_id}") - - if "mqtt" not in hass.config.components: - _logger.warning("MQTT not yet available. Retrying later...") - raise ConfigEntryNotReady("MQTT integration is not ready") - hass.data.setdefault(DOMAIN, {}) if entry.entry_id not in hass.data[DOMAIN] and entry.data: @@ -41,10 +23,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): _logger.info(f"hass.data[DOMAIN] after adding entry data: {hass.data[DOMAIN]}") + # Forward the setup to the sensor and button platforms using the new method. + # Note: async_forward_entry_setups must always be awaited. await hass.config_entries.async_forward_entry_setups(entry, ["sensor", "button"]) _logger.info(f"hass.data[DOMAIN] before async_setup_services: {hass.data[DOMAIN]}") + # Setup the services _logger.info("Starting setup of services") await async_setup_services(hass) _logger.info("Finished setup of services") @@ -64,8 +49,11 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" _logger.info(f"Starting unload of config entry with ID: {entry.entry_id}") + # Remove the sensor platform + _logger.info("Removing sensor platform") await hass.config_entries.async_forward_entry_unload(entry, "sensor") + # Ensure hass.data[DOMAIN] is a dictionary before popping if isinstance(hass.data.get(DOMAIN, {}), dict): hass.data[DOMAIN].pop(entry.entry_id, None) diff --git a/custom_components/saas/button.py b/custom_components/saas/button.py index 96a82ca..945dcb2 100644 --- a/custom_components/saas/button.py +++ b/custom_components/saas/button.py @@ -572,4 +572,4 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # Add the entities async_add_entities(entities) - return True \ No newline at end of file + # _LOGGER.debug("SAAS Sleep Tracking buttons set up successfully") \ No newline at end of file diff --git a/custom_components/saas/manifest.json b/custom_components/saas/manifest.json index 4f2ad3a..7de1702 100644 --- a/custom_components/saas/manifest.json +++ b/custom_components/saas/manifest.json @@ -3,7 +3,6 @@ "name": "SAAS - Sleep As Android Status", "codeowners": ["@sudoxnym"], "config_flow": true, - "platforms": ["sensor", "button"], "dependencies": ["mqtt", "mobile_app"], "documentation": "https://www.github.com/sudoxnym/saas", "issue_tracker": "https://www.github.com/sudoxnym/saas/issues", diff --git a/custom_components/saas/sensor.py b/custom_components/saas/sensor.py index 3c16274..00cc7e4 100644 --- a/custom_components/saas/sensor.py +++ b/custom_components/saas/sensor.py @@ -833,4 +833,3 @@ async def async_setup_entry(hass, entry, async_add_entities): await entity.async_setup() async_add_entities(entities) - return True \ No newline at end of file diff --git a/custom_components/saas/services.py b/custom_components/saas/services.py index 5a3040a..d61ad18 100644 --- a/custom_components/saas/services.py +++ b/custom_components/saas/services.py @@ -50,7 +50,7 @@ class SAASService: except Exception as e: _LOGGER.error(f"Error occurred while calling service: {e}") -async def async_setup_services(hass: HomeAssistant) -> bool: +async def async_setup_services(hass: HomeAssistant) -> None: """Set up services for the SAAS component.""" _LOGGER.info(f"Setting up services for {DOMAIN}") # Register the service for each entry @@ -70,6 +70,4 @@ async def async_setup_services(hass: HomeAssistant) -> bool: _LOGGER.warning(f"No notify_target found for name: {name}. Skipping service registration.") else: _LOGGER.warning(f"No entry data found for entry_id: {entry_id}") - _LOGGER.info(f"Finished setting up services for {DOMAIN}") - - return True \ No newline at end of file + _LOGGER.info(f"Finished setting up services for {DOMAIN}") \ No newline at end of file