Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CODEOWNERS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion homeassistant/components/husqvarna_automower/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "cloud_push",
"loggers": ["aioautomower"],
"quality_scale": "silver",
"requirements": ["aioautomower==2.7.4"]
"requirements": ["aioautomower==2.7.5"]
}
97 changes: 97 additions & 0 deletions homeassistant/components/mitsubishi_comfort/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""Mitsubishi Comfort integration for Home Assistant."""

from __future__ import annotations

import asyncio
import logging

from mitsubishi_comfort import (
DeviceInfo,
IndoorUnit,
KumoStation,
MitsubishiCloudAccount,
)
from mitsubishi_comfort.exceptions import AuthenticationError, DeviceConnectionError

from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryError, ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .const import DEFAULT_CONNECT_TIMEOUT, DEFAULT_RESPONSE_TIMEOUT, DOMAIN, PLATFORMS
from .coordinator import MitsubishiComfortConfigEntry, MitsubishiComfortCoordinator

_LOGGER = logging.getLogger(__name__)


def _make_device(
info: DeviceInfo,
serial: str,
session,
) -> IndoorUnit | KumoStation:
"""Create the appropriate device instance from DeviceInfo."""
cls = IndoorUnit if info.is_indoor_unit else KumoStation
return cls(
name=info.label,
address=info.address,
password_b64=info.password,
crypto_serial_hex=info.crypto_serial,
serial=serial,
connect_timeout=DEFAULT_CONNECT_TIMEOUT,
response_timeout=DEFAULT_RESPONSE_TIMEOUT,
session=session,
)


async def async_setup_entry(
hass: HomeAssistant, entry: MitsubishiComfortConfigEntry
) -> bool:
"""Set up Mitsubishi Comfort from a config entry."""
session = async_get_clientsession(hass)
account = MitsubishiCloudAccount(
entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD], session=session
)

try:
await account.login()
devices = await account.discover_devices()
except AuthenticationError as err:
raise ConfigEntryError("Mitsubishi cloud authentication failed") from err
except DeviceConnectionError as err:
raise ConfigEntryNotReady("Cannot reach Mitsubishi cloud") from err

if not devices:
raise ConfigEntryError(
translation_domain=DOMAIN,
translation_key="no_devices",
)

coordinators: dict[str, MitsubishiComfortCoordinator] = {}
for serial, info in devices.items():
if not info.address or not info.password or not info.crypto_serial:
_LOGGER.warning("Device %s missing credentials, skipping", info.label)
continue
device = _make_device(info, serial, session)
coordinators[serial] = MitsubishiComfortCoordinator(
hass, entry, device, info.mac
)

await asyncio.gather(
*(c.async_config_entry_first_refresh() for c in coordinators.values())
)

entry.runtime_data = coordinators
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True


async def async_unload_entry(
hass: HomeAssistant, entry: MitsubishiComfortConfigEntry
) -> bool:
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
await asyncio.gather(
*(c.device.close() for c in entry.runtime_data.values()),
return_exceptions=True,
)
return unload_ok
Loading
Loading