Add files via upload

This commit is contained in:
sudoxnym 2025-04-14 18:17:05 -06:00 committed by GitHub
parent 71d8c6dd2b
commit f8f8c7927d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 9 additions and 25 deletions

View file

@ -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)

View file

@ -572,4 +572,4 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
# Add the entities
async_add_entities(entities)
return True
# _LOGGER.debug("SAAS Sleep Tracking buttons set up successfully")

View file

@ -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",

View file

@ -833,4 +833,3 @@ async def async_setup_entry(hass, entry, async_add_entities):
await entity.async_setup()
async_add_entities(entities)
return True

View file

@ -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
@ -71,5 +71,3 @@ async def async_setup_services(hass: HomeAssistant) -> bool:
else:
_LOGGER.warning(f"No entry data found for entry_id: {entry_id}")
_LOGGER.info(f"Finished setting up services for {DOMAIN}")
return True