core/homeassistant/components/triggercmd/__init__.py

37 lines
1.0 KiB
Python
Raw Normal View History

Add TRIGGERcmd integration (#121268) * Initial commit with errors * Commitable * Use triggercmd user id as hub name * Validate the token * Use switch type, no trigger yet * Working integration * Use triggercmd module instead of httpx * Add tests for triggercmd integration * Add triggercmd to requirements_test_all.txt * Add untested triggercmd files to .coveragerc * Implement cgarwood's PR suggestions * Address PR feedback * Update homeassistant/components/triggercmd/config_flow.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/triggercmd/hub.py Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/triggercmd/strings.json Co-authored-by: Robert Resch <robert@resch.dev> * Update homeassistant/components/triggercmd/hub.py Co-authored-by: Robert Resch <robert@resch.dev> * Get user id via triggercmd module, and better check for status 200 code * PR feedback fixes * Update homeassistant/components/triggercmd/switch.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/triggercmd/switch.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * More PR feedback fixes * Update homeassistant/components/triggercmd/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/triggercmd/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/triggercmd/switch.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * More PR feedback fixes * Update tests/components/triggercmd/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Changes for PR feedback * Changes to address PR comments * Fix connection error when no internet * Update homeassistant/components/triggercmd/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/triggercmd/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/triggercmd/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/triggercmd/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/triggercmd/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Updates for PR feedback * Update tests/components/triggercmd/test_config_flow.py --------- Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-11 13:49:37 +00:00
"""The TRIGGERcmd component."""
from __future__ import annotations
from triggercmd import client, ha
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from .const import CONF_TOKEN
PLATFORMS = [
Platform.SWITCH,
]
type TriggercmdConfigEntry = ConfigEntry[ha.Hub]
async def async_setup_entry(hass: HomeAssistant, entry: TriggercmdConfigEntry) -> bool:
"""Set up TRIGGERcmd from a config entry."""
hub = ha.Hub(entry.data[CONF_TOKEN])
status_code = await client.async_connection_test(entry.data[CONF_TOKEN])
if status_code != 200:
raise ConfigEntryNotReady
entry.runtime_data = hub
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: TriggercmdConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)