* Initial version * Baseline release * Refactor based on first PR feedback * Refactoring based on second PR feedback * Initial version * Baseline release * Refactor based on first PR feedback * Refactoring based on second PR feedback * Refactoring based on PR feedback * Refactoring based on PR feedback * Remove extra attribute soil type Soil type isn't really a sensor, but more like a configuration entity. Move soil type to a different PR to keep this PR simpler. * Refactor SensoterraSensor to a named tuple * Implement feedback on PR * Remove .coveragerc * Add async_set_unique_id to config flow * Small fix based on feedback * Add test form unique_id * Fix * Fix --------- Co-authored-by: Joostlek <joostlek@outlook.com>
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
"""The Sensoterra integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from sensoterra.customerapi import CustomerApi
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import CONF_TOKEN, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .coordinator import SensoterraCoordinator
|
|
|
|
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
|
|
|
type SensoterraConfigEntry = ConfigEntry[SensoterraCoordinator]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: SensoterraConfigEntry) -> bool:
|
|
"""Set up Sensoterra platform based on a configuration entry."""
|
|
|
|
# Create a coordinator and add an API instance to it. Store the coordinator
|
|
# in the configuration entry.
|
|
api = CustomerApi()
|
|
api.set_language(hass.config.language)
|
|
api.set_token(entry.data[CONF_TOKEN])
|
|
|
|
coordinator = SensoterraCoordinator(hass, api)
|
|
await coordinator.async_config_entry_first_refresh()
|
|
entry.runtime_data = coordinator
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: SensoterraConfigEntry) -> bool:
|
|
"""Unload the configuration entry."""
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|