mirror of
https://github.com/sudoxnym/sleepd.git
synced 2026-04-14 11:37:11 +00:00
Add files via upload
WOO Fixed the ghost error!
This commit is contained in:
parent
0213d6b688
commit
71d8c6dd2b
6 changed files with 25 additions and 9 deletions
|
|
@ -2,10 +2,23 @@ import asyncio
|
||||||
import logging
|
import logging
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from .services import async_setup_services # Import the service setup function
|
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__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: dict):
|
async def async_setup(hass: HomeAssistant, config: dict):
|
||||||
|
|
@ -16,6 +29,11 @@ async def async_setup(hass: HomeAssistant, config: dict):
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Set up a config entry."""
|
"""Set up a config entry."""
|
||||||
_logger.info(f"Starting setup of config entry with ID: {entry.entry_id}")
|
_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, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
|
||||||
if entry.entry_id not in hass.data[DOMAIN] and entry.data:
|
if entry.entry_id not in hass.data[DOMAIN] and entry.data:
|
||||||
|
|
@ -23,13 +41,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
|
|
||||||
_logger.info(f"hass.data[DOMAIN] after adding entry data: {hass.data[DOMAIN]}")
|
_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"])
|
await hass.config_entries.async_forward_entry_setups(entry, ["sensor", "button"])
|
||||||
|
|
||||||
_logger.info(f"hass.data[DOMAIN] before async_setup_services: {hass.data[DOMAIN]}")
|
_logger.info(f"hass.data[DOMAIN] before async_setup_services: {hass.data[DOMAIN]}")
|
||||||
|
|
||||||
# Setup the services
|
|
||||||
_logger.info("Starting setup of services")
|
_logger.info("Starting setup of services")
|
||||||
await async_setup_services(hass)
|
await async_setup_services(hass)
|
||||||
_logger.info("Finished setup of services")
|
_logger.info("Finished setup of services")
|
||||||
|
|
@ -49,11 +64,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
_logger.info(f"Starting unload of config entry with ID: {entry.entry_id}")
|
_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")
|
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):
|
if isinstance(hass.data.get(DOMAIN, {}), dict):
|
||||||
hass.data[DOMAIN].pop(entry.entry_id, None)
|
hass.data[DOMAIN].pop(entry.entry_id, None)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -572,4 +572,4 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
|
|
||||||
# Add the entities
|
# Add the entities
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
# _LOGGER.debug("SAAS Sleep Tracking buttons set up successfully")
|
return True
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
"name": "SAAS - Sleep As Android Status",
|
"name": "SAAS - Sleep As Android Status",
|
||||||
"codeowners": ["@sudoxnym"],
|
"codeowners": ["@sudoxnym"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
|
"platforms": ["sensor", "button"],
|
||||||
"dependencies": ["mqtt", "mobile_app"],
|
"dependencies": ["mqtt", "mobile_app"],
|
||||||
"documentation": "https://www.github.com/sudoxnym/saas",
|
"documentation": "https://www.github.com/sudoxnym/saas",
|
||||||
"issue_tracker": "https://www.github.com/sudoxnym/saas/issues",
|
"issue_tracker": "https://www.github.com/sudoxnym/saas/issues",
|
||||||
|
|
|
||||||
|
|
@ -833,3 +833,4 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
||||||
await entity.async_setup()
|
await entity.async_setup()
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
return True
|
||||||
|
|
@ -50,7 +50,7 @@ class SAASService:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_LOGGER.error(f"Error occurred while calling service: {e}")
|
_LOGGER.error(f"Error occurred while calling service: {e}")
|
||||||
|
|
||||||
async def async_setup_services(hass: HomeAssistant) -> None:
|
async def async_setup_services(hass: HomeAssistant) -> bool:
|
||||||
"""Set up services for the SAAS component."""
|
"""Set up services for the SAAS component."""
|
||||||
_LOGGER.info(f"Setting up services for {DOMAIN}")
|
_LOGGER.info(f"Setting up services for {DOMAIN}")
|
||||||
# Register the service for each entry
|
# Register the service for each entry
|
||||||
|
|
@ -70,4 +70,6 @@ async def async_setup_services(hass: HomeAssistant) -> None:
|
||||||
_LOGGER.warning(f"No notify_target found for name: {name}. Skipping service registration.")
|
_LOGGER.warning(f"No notify_target found for name: {name}. Skipping service registration.")
|
||||||
else:
|
else:
|
||||||
_LOGGER.warning(f"No entry data found for entry_id: {entry_id}")
|
_LOGGER.warning(f"No entry data found for entry_id: {entry_id}")
|
||||||
_LOGGER.info(f"Finished setting up services for {DOMAIN}")
|
_LOGGER.info(f"Finished setting up services for {DOMAIN}")
|
||||||
|
|
||||||
|
return True
|
||||||
0
custom_components/saas/services.yaml
Normal file
0
custom_components/saas/services.yaml
Normal file
Loading…
Reference in a new issue