1 """The MELCloud Climate integration."""
3 from __future__
import annotations
6 from datetime
import timedelta
10 from aiohttp
import ClientConnectionError, ClientResponseError
11 from pymelcloud
import Device, get_devices
12 from pymelcloud.atw_device
import Zone
22 from .const
import DOMAIN
24 _LOGGER = logging.getLogger(__name__)
28 PLATFORMS = [Platform.CLIMATE, Platform.SENSOR, Platform.WATER_HEATER]
32 """Establish connection with MELClooud."""
36 except ClientResponseError
as ex:
37 if isinstance(ex, ClientResponseError)
and ex.code == 401:
38 raise ConfigEntryAuthFailed
from ex
39 raise ConfigEntryNotReady
from ex
40 except (TimeoutError, ClientConnectionError)
as ex:
41 raise ConfigEntryNotReady
from ex
43 hass.data.setdefault(DOMAIN, {}).
update({entry.entry_id: mel_devices})
44 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
49 """Unload a config entry."""
50 unload_ok = await hass.config_entries.async_unload_platforms(
51 config_entry, PLATFORMS
53 hass.data[DOMAIN].pop(config_entry.entry_id)
54 if not hass.data[DOMAIN]:
60 """MELCloud Device instance."""
63 """Construct a device wrapper."""
65 self.
namename = device.name
68 @Throttle(MIN_TIME_BETWEEN_UPDATES)
70 """Pull the latest data from MELCloud."""
74 except ClientConnectionError:
75 _LOGGER.warning(
"Connection failed for %s", self.
namename)
78 async
def async_set(self, properties: dict[str, Any]):
79 """Write state changes to the MELCloud API."""
81 await self.
devicedevice.set(properties)
83 except ClientConnectionError:
84 _LOGGER.warning(
"Connection failed for %s", self.
namename)
89 """Return True if entity is available."""
94 """Return device ID."""
95 return self.
devicedevice.device_id
99 """Return building ID of the device."""
100 return self.
devicedevice.building_id
104 """Return a device description for device registry."""
106 if (unit_infos := self.
devicedevice.units)
is not None:
107 model =
", ".join([x[
"model"]
for x
in unit_infos
if x[
"model"]])
109 connections={(CONNECTION_NETWORK_MAC, self.
devicedevice.mac)},
110 identifiers={(DOMAIN, f
"{self.device.mac}-{self.device.serial}")},
111 manufacturer=
"Mitsubishi Electric",
117 """Return a zone device description for device registry."""
120 identifiers={(DOMAIN, f
"{dev.mac}-{dev.serial}-{zone.zone_index}")},
121 manufacturer=
"Mitsubishi Electric",
122 model=
"ATW zone device",
123 name=f
"{self.name} {zone.name}",
124 via_device=(DOMAIN, f
"{dev.mac}-{dev.serial}"),
129 hass: HomeAssistant, token: str
130 ) -> dict[str, list[MelCloudDevice]]:
131 """Query connected devices from MELCloud."""
133 async
with asyncio.timeout(10):
134 all_devices = await get_devices(
137 conf_update_interval=
timedelta(minutes=30),
138 device_set_debounce=
timedelta(seconds=2),
140 wrapped_devices: dict[str, list[MelCloudDevice]] = {}
141 for device_type, devices
in all_devices.items():
142 wrapped_devices[device_type] = [
MelCloudDevice(device)
for device
in devices]
143 return wrapped_devices
None __init__(self, Device device)
def async_set(self, dict[str, Any] properties)
def async_update(self, **kwargs)
DeviceInfo zone_device_info(self, Zone zone)
DeviceInfo device_info(self)
IssData update(pyiss.ISS iss)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry config_entry)
dict[str, list[MelCloudDevice]] mel_devices_setup(HomeAssistant hass, str token)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)