Skip to content

Commit 1017f43

Browse files
Created first version
1 parent f5ea5a9 commit 1017f43

File tree

14 files changed

+291
-319
lines changed

14 files changed

+291
-319
lines changed

config/configuration.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# https://www.home-assistant.io/integrations/default_config/
2-
default_config:
2+
# default_config:
3+
4+
bluetooth:
5+
config:
6+
dhcp:
7+
history:
8+
usb:
9+
zeroconf:
310

411
# https://www.home-assistant.io/integrations/homeassistant/
512
homeassistant:
@@ -9,4 +16,4 @@ homeassistant:
916
logger:
1017
default: info
1118
logs:
12-
custom_components.panda_status: debug
19+
custom_components.panda_status: debug

custom_components/panda_status/__init__.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,40 @@
77

88
from __future__ import annotations
99

10-
from datetime import timedelta
1110
from typing import TYPE_CHECKING
1211

13-
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
14-
from homeassistant.helpers.aiohttp_client import async_get_clientsession
12+
from homeassistant.const import CONF_URL, Platform
1513
from homeassistant.loader import async_get_loaded_integration
1614

17-
from .api import IntegrationBlueprintApiClient
1815
from .const import DOMAIN, LOGGER
19-
from .coordinator import BlueprintDataUpdateCoordinator
20-
from .data import IntegrationBlueprintData
16+
from .coordinator import PandaStatusDataUpdateCoordinator
17+
from .data import PandaStatusData
18+
from .websocket import PandaStatusWebSocket
2119

2220
if TYPE_CHECKING:
2321
from homeassistant.core import HomeAssistant
2422

25-
from .data import IntegrationBlueprintConfigEntry
23+
from .data import PandaStatusConfigEntry
2624

2725
PLATFORMS: list[Platform] = [
2826
Platform.SENSOR,
29-
Platform.BINARY_SENSOR,
3027
Platform.SWITCH,
3128
]
3229

3330

3431
# https://developers.home-assistant.io/docs/config_entries_index/#setting-up-an-entry
3532
async def async_setup_entry(
3633
hass: HomeAssistant,
37-
entry: IntegrationBlueprintConfigEntry,
34+
entry: PandaStatusConfigEntry,
3835
) -> bool:
3936
"""Set up this integration using UI."""
40-
coordinator = BlueprintDataUpdateCoordinator(
37+
coordinator = PandaStatusDataUpdateCoordinator(
4138
hass=hass,
4239
logger=LOGGER,
4340
name=DOMAIN,
44-
update_interval=timedelta(hours=1),
4541
)
46-
entry.runtime_data = IntegrationBlueprintData(
47-
client=IntegrationBlueprintApiClient(
48-
username=entry.data[CONF_USERNAME],
49-
password=entry.data[CONF_PASSWORD],
50-
session=async_get_clientsession(hass),
51-
),
42+
entry.runtime_data = PandaStatusData(
43+
client=PandaStatusWebSocket(url=entry.data[CONF_URL], session=None),
5244
integration=async_get_loaded_integration(hass, entry.domain),
5345
coordinator=coordinator,
5446
)
@@ -64,15 +56,15 @@ async def async_setup_entry(
6456

6557
async def async_unload_entry(
6658
hass: HomeAssistant,
67-
entry: IntegrationBlueprintConfigEntry,
59+
entry: PandaStatusConfigEntry,
6860
) -> bool:
6961
"""Handle removal of an entry."""
7062
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
7163

7264

7365
async def async_reload_entry(
7466
hass: HomeAssistant,
75-
entry: IntegrationBlueprintConfigEntry,
67+
entry: PandaStatusConfigEntry,
7668
) -> None:
7769
"""Reload config entry."""
7870
await hass.config_entries.async_reload(entry.entry_id)

custom_components/panda_status/api.py

Lines changed: 0 additions & 101 deletions
This file was deleted.

custom_components/panda_status/binary_sensor.py

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
"""Adds config flow for Blueprint."""
1+
"""Adds config flow for PandaStatus."""
22

33
from __future__ import annotations
44

55
import voluptuous as vol
66
from homeassistant import config_entries
7-
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
7+
from homeassistant.const import CONF_URL
88
from homeassistant.helpers import selector
9-
from homeassistant.helpers.aiohttp_client import async_create_clientsession
109
from slugify import slugify
1110

12-
from .api import (
13-
IntegrationBlueprintApiClient,
14-
IntegrationBlueprintApiClientAuthenticationError,
15-
IntegrationBlueprintApiClientCommunicationError,
16-
IntegrationBlueprintApiClientError,
17-
)
1811
from .const import DOMAIN, LOGGER
12+
from .websocket import (
13+
PandaStatusWebSocket,
14+
PandaStatusWebsocketCommunicationError,
15+
PandaStatusWebsocketError,
16+
)
1917

2018

21-
class BlueprintFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
22-
"""Config flow for Blueprint."""
19+
class PandaStatusFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
20+
"""Config flow for PandaStatus."""
2321

2422
VERSION = 1
2523

@@ -32,58 +30,40 @@ async def async_step_user(
3230
if user_input is not None:
3331
try:
3432
await self._test_credentials(
35-
username=user_input[CONF_USERNAME],
36-
password=user_input[CONF_PASSWORD],
33+
url=user_input[CONF_URL],
3734
)
38-
except IntegrationBlueprintApiClientAuthenticationError as exception:
39-
LOGGER.warning(exception)
40-
_errors["base"] = "auth"
41-
except IntegrationBlueprintApiClientCommunicationError as exception:
35+
except PandaStatusWebsocketCommunicationError as exception:
4236
LOGGER.error(exception)
4337
_errors["base"] = "connection"
44-
except IntegrationBlueprintApiClientError as exception:
38+
except PandaStatusWebsocketError as exception:
4539
LOGGER.exception(exception)
4640
_errors["base"] = "unknown"
4741
else:
48-
await self.async_set_unique_id(
49-
## Do NOT use this in production code
50-
## The unique_id should never be something that can change
51-
## https://developers.home-assistant.io/docs/config_entries_config_flow_handler#unique-ids
52-
unique_id=slugify(user_input[CONF_USERNAME])
53-
)
42+
await self.async_set_unique_id(unique_id=slugify(user_input[CONF_URL]))
5443
self._abort_if_unique_id_configured()
44+
5545
return self.async_create_entry(
56-
title=user_input[CONF_USERNAME],
57-
data=user_input,
46+
title=user_input[CONF_URL], data=user_input
5847
)
5948

6049
return self.async_show_form(
6150
step_id="user",
6251
data_schema=vol.Schema(
6352
{
6453
vol.Required(
65-
CONF_USERNAME,
66-
default=(user_input or {}).get(CONF_USERNAME, vol.UNDEFINED),
54+
CONF_URL,
55+
default=(user_input or {}).get(CONF_URL, vol.UNDEFINED),
6756
): selector.TextSelector(
6857
selector.TextSelectorConfig(
6958
type=selector.TextSelectorType.TEXT,
7059
),
7160
),
72-
vol.Required(CONF_PASSWORD): selector.TextSelector(
73-
selector.TextSelectorConfig(
74-
type=selector.TextSelectorType.PASSWORD,
75-
),
76-
),
7761
},
7862
),
7963
errors=_errors,
8064
)
8165

82-
async def _test_credentials(self, username: str, password: str) -> None:
66+
async def _test_credentials(self, url: str) -> None:
8367
"""Validate credentials."""
84-
client = IntegrationBlueprintApiClient(
85-
username=username,
86-
password=password,
87-
session=async_create_clientsession(self.hass),
88-
)
68+
client = PandaStatusWebSocket(url=url, session=None)
8969
await client.async_get_data()

custom_components/panda_status/const.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@
55
LOGGER: Logger = getLogger(__package__)
66

77
DOMAIN = "panda_status"
8-
ATTRIBUTION = "Data provided by http://jsonplaceholder.typicode.com/"

0 commit comments

Comments
 (0)