Skip to content

Commit 21a54d8

Browse files
authored
Merge pull request #112 from explosivo22/dev
Change folder structure
2 parents 0c0765b + 4181a83 commit 21a54d8

File tree

12 files changed

+486
-486
lines changed

12 files changed

+486
-486
lines changed

custom_components/rinnai/__init__.py renamed to custom_components/rinnaicontrolr-ha/__init__.py

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,88 @@
11
<<<<<<< HEAD:custom_components/rinnaicontrolr-ha/__init__.py
2-
import logging
3-
import asyncio
4-
5-
from aiorinnai import API
6-
from aiorinnai.api import Unauthenticated
7-
from aiorinnai.errors import RequestError
8-
9-
from homeassistant.config_entries import ConfigEntry
10-
from homeassistant.const import CONF_EMAIL
11-
from homeassistant.core import HomeAssistant
12-
from homeassistant.exceptions import ConfigEntryNotReady, ConfigEntryAuthFailed
13-
from homeassistant.helpers.aiohttp_client import async_get_clientsession
14-
from homeassistant.components.water_heater import DOMAIN as WATER_HEATER_DOMAIN
15-
from homeassistant.helpers.device_registry import DeviceEntry
16-
17-
from .const import (
18-
CLIENT,
19-
DOMAIN,
20-
CONF_ACCESS_TOKEN,
21-
CONF_REFRESH_TOKEN,
22-
)
23-
from .device import RinnaiDeviceDataUpdateCoordinator
24-
25-
_LOGGER = logging.getLogger(__name__)
26-
27-
PLATFORMS = ["water_heater", "binary_sensor", "sensor"]
28-
29-
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
30-
"""Set up Rinnai from config entry"""
31-
hass.data.setdefault(DOMAIN, {})
32-
hass.data[DOMAIN][entry.entry_id] = {}
33-
34-
_LOGGER.debug(entry.data[CONF_EMAIL])
35-
36-
hass.data[DOMAIN][entry.entry_id][CLIENT] = client = API()
37-
38-
try:
39-
await client.async_renew_access_token(entry.data[CONF_EMAIL], entry.data[CONF_ACCESS_TOKEN], entry.data[CONF_REFRESH_TOKEN])
40-
user_info = await client.user.get_info()
41-
_LOGGER.debug("User info retrieved: %s", user_info)
42-
except Unauthenticated as err:
43-
_LOGGER.error("Authentication error: %s", err)
44-
raise ConfigEntryAuthFailed from err
45-
except RequestError as err:
46-
_LOGGER.error("Request error: %s", err)
47-
raise ConfigEntryNotReady from err
48-
49-
devices = user_info.get("devices", {}).get("items", [])
50-
if not devices:
51-
_LOGGER.error("No devices found in user info")
52-
raise ConfigEntryNotReady("No devices found")
53-
54-
hass.data[DOMAIN][entry.entry_id]["devices"] = [
55-
RinnaiDeviceDataUpdateCoordinator(hass, client, device["id"], entry.options)
56-
for device in devices
57-
]
58-
59-
tasks = [device.async_refresh() for device in hass.data[DOMAIN][entry.entry_id]["devices"]]
60-
await asyncio.gather(*tasks)
61-
62-
if not entry.options:
63-
await _async_options_updated(hass, entry)
64-
65-
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
66-
67-
entry.async_on_unload(entry.add_update_listener(_async_options_updated))
68-
69-
return True
70-
71-
async def _async_options_updated(hass: HomeAssistant, entry: ConfigEntry):
72-
"""Update options."""
73-
await hass.config_entries.async_reload(entry.entry_id)
74-
75-
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
76-
"""Unload a config entry."""
77-
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
78-
if unload_ok:
79-
hass.data[DOMAIN].pop(entry.entry_id)
80-
return unload_ok
81-
82-
async def async_remove_config_entry_device(
83-
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: DeviceEntry
84-
) -> bool:
85-
"""Remove a config entry from a device."""
2+
import logging
3+
import asyncio
4+
5+
from aiorinnai import API
6+
from aiorinnai.api import Unauthenticated
7+
from aiorinnai.errors import RequestError
8+
9+
from homeassistant.config_entries import ConfigEntry
10+
from homeassistant.const import CONF_EMAIL
11+
from homeassistant.core import HomeAssistant
12+
from homeassistant.exceptions import ConfigEntryNotReady, ConfigEntryAuthFailed
13+
from homeassistant.helpers.aiohttp_client import async_get_clientsession
14+
from homeassistant.components.water_heater import DOMAIN as WATER_HEATER_DOMAIN
15+
from homeassistant.helpers.device_registry import DeviceEntry
16+
17+
from .const import (
18+
CLIENT,
19+
DOMAIN,
20+
CONF_ACCESS_TOKEN,
21+
CONF_REFRESH_TOKEN,
22+
)
23+
from .device import RinnaiDeviceDataUpdateCoordinator
24+
25+
_LOGGER = logging.getLogger(__name__)
26+
27+
PLATFORMS = ["water_heater", "binary_sensor", "sensor"]
28+
29+
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
30+
"""Set up Rinnai from config entry"""
31+
hass.data.setdefault(DOMAIN, {})
32+
hass.data[DOMAIN][entry.entry_id] = {}
33+
34+
_LOGGER.debug(entry.data[CONF_EMAIL])
35+
36+
hass.data[DOMAIN][entry.entry_id][CLIENT] = client = API()
37+
38+
try:
39+
await client.async_renew_access_token(entry.data[CONF_EMAIL], entry.data[CONF_ACCESS_TOKEN], entry.data[CONF_REFRESH_TOKEN])
40+
user_info = await client.user.get_info()
41+
_LOGGER.debug("User info retrieved: %s", user_info)
42+
except Unauthenticated as err:
43+
_LOGGER.error("Authentication error: %s", err)
44+
raise ConfigEntryAuthFailed from err
45+
except RequestError as err:
46+
_LOGGER.error("Request error: %s", err)
47+
raise ConfigEntryNotReady from err
48+
49+
devices = user_info.get("devices", {}).get("items", [])
50+
if not devices:
51+
_LOGGER.error("No devices found in user info")
52+
raise ConfigEntryNotReady("No devices found")
53+
54+
hass.data[DOMAIN][entry.entry_id]["devices"] = [
55+
RinnaiDeviceDataUpdateCoordinator(hass, client, device["id"], entry.options)
56+
for device in devices
57+
]
58+
59+
tasks = [device.async_refresh() for device in hass.data[DOMAIN][entry.entry_id]["devices"]]
60+
await asyncio.gather(*tasks)
61+
62+
if not entry.options:
63+
await _async_options_updated(hass, entry)
64+
65+
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
66+
67+
entry.async_on_unload(entry.add_update_listener(_async_options_updated))
68+
69+
return True
70+
71+
async def _async_options_updated(hass: HomeAssistant, entry: ConfigEntry):
72+
"""Update options."""
73+
await hass.config_entries.async_reload(entry.entry_id)
74+
75+
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
76+
"""Unload a config entry."""
77+
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
78+
if unload_ok:
79+
hass.data[DOMAIN].pop(entry.entry_id)
80+
return unload_ok
81+
82+
async def async_remove_config_entry_device(
83+
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: DeviceEntry
84+
) -> bool:
85+
"""Remove a config entry from a device."""
8686
return True
8787
=======
8888
import logging

0 commit comments

Comments
 (0)