Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Compit integration #132164

Draft
wants to merge 34 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8a12527
Add Compit integration
Przemko92 Dec 3, 2024
e26b4d5
Update CODEOWNERS
Przemko92 Dec 4, 2024
15596d2
Removed all platforms except climate
Przemko92 Dec 4, 2024
bc5f03d
Merge branch 'dev' into compit-integration
abmantis Dec 4, 2024
86406ff
Update aiofiles
Przemko92 Dec 4, 2024
e1fa03d
Change requirements to fixed version
Przemko92 Dec 4, 2024
8df7a6a
Code review changes
Przemko92 Dec 5, 2024
21e53ff
Small refactor
Przemko92 Dec 5, 2024
e06a1c1
Fix warnings
Przemko92 Dec 5, 2024
ffce0c6
Update strings
Przemko92 Dec 5, 2024
bb4dfaf
Fix warnings
Przemko92 Dec 5, 2024
2207247
Update strings
Przemko92 Dec 5, 2024
b982852
Update strings
Przemko92 Dec 5, 2024
8c7a2fa
Fix unit tests
Przemko92 Dec 6, 2024
240caa8
Merge branch 'home-assistant:dev' into compit-integration
Przemko92 Dec 6, 2024
8f8bb66
Code review suggestions
Przemko92 Dec 7, 2024
3fc42ec
Merge branch 'home-assistant:dev' into compit-integration
Przemko92 Dec 7, 2024
5edc862
Quality scale
Przemko92 Dec 7, 2024
abdbf2a
Refactor configflow. Cleanup unused properties
Przemko92 Dec 11, 2024
c2c25e7
Merge branch 'home-assistant:dev' into compit-integration
Przemko92 Dec 11, 2024
634cb11
Catch unexpected exception
Przemko92 Dec 11, 2024
aedd493
Fix strongly typed error
Przemko92 Dec 11, 2024
31f3f92
Requirements
Przemko92 Dec 11, 2024
ae620b6
Fix strongly typed error
Przemko92 Dec 11, 2024
7dfcc2a
Code review suggestions
Przemko92 Dec 27, 2024
83ef1e3
Merge branch 'home-assistant:dev' into compit-integration
Przemko92 Dec 27, 2024
e145bc5
Merge branch 'dev' into compit-integration
Przemko92 Dec 27, 2024
eabcd71
Update api lib
Przemko92 Dec 27, 2024
9f0f8b1
Fix types
Przemko92 Dec 27, 2024
cbe17bd
Fix types
Przemko92 Dec 27, 2024
f06f967
Fix types
Przemko92 Dec 27, 2024
299b4bd
Fix types
Przemko92 Dec 27, 2024
b67c965
Fix unit tests
Przemko92 Dec 28, 2024
3d7df31
Fix unit tests
Przemko92 Dec 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ homeassistant.components.climate.*
homeassistant.components.cloud.*
homeassistant.components.co2signal.*
homeassistant.components.command_line.*
homeassistant.components.compit.*
homeassistant.components.config.*
homeassistant.components.configurator.*
homeassistant.components.counter.*
Expand Down
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ build.json @home-assistant/supervisor
/tests/components/command_line/ @gjohansson-ST
/homeassistant/components/compensation/ @Petro31
/tests/components/compensation/ @Petro31
/homeassistant/components/compit/ @Przemko92
/tests/components/compit/ @Przemko92
/homeassistant/components/config/ @home-assistant/core
/tests/components/config/ @home-assistant/core
/homeassistant/components/configurator/ @home-assistant/core
Expand Down
64 changes: 64 additions & 0 deletions homeassistant/components/compit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""The Compit integration."""

from __future__ import annotations

import logging

from compit_inext_api import (
CannotConnect,
CompitAPI,
DeviceDefinitionsLoader,
InvalidAuth,
)

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .const import PLATFORMS
from .coordinator import CompitDataUpdateCoordinator

_LOGGER: logging.Logger = logging.getLogger(__package__)

type CompitConfigEntry = ConfigEntry[CompitDataUpdateCoordinator]


async def async_setup_entry(hass: HomeAssistant, entry: CompitConfigEntry) -> bool:
"""Set up Compit from a config entry."""

session = async_get_clientsession(hass)
api = CompitAPI(entry.data["email"], entry.data["password"], session)
try:
Przemko92 marked this conversation as resolved.
Show resolved Hide resolved
system_info = await api.authenticate()

if system_info is False:
_LOGGER.warning("Compit api error")
Przemko92 marked this conversation as resolved.
Show resolved Hide resolved
return False
Przemko92 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


device_definitions = await DeviceDefinitionsLoader.get_device_definitions(
hass.config.language
)

coordinator = CompitDataUpdateCoordinator(
hass, system_info.gates, api, device_definitions
)
await coordinator.async_config_entry_first_refresh()
entry.runtime_data = coordinator
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
except CannotConnect as e:
_LOGGER.warning("Cannot connect: %s", e)
return False
Przemko92 marked this conversation as resolved.
Show resolved Hide resolved
except InvalidAuth as e:
raise ConfigEntryAuthFailed(
f"Invalid credentials for {entry.data["email"]}"
) from e
except ValueError as e:
_LOGGER.warning("Value error: %s", e)
return False
return True


async def async_unload_entry(hass: HomeAssistant, entry: CompitConfigEntry) -> bool:
"""Unload an entry for the Compit integration."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
Loading