Skip to content

Commit 3efdbfe

Browse files
committed
commented code cleanup
removed error logging i was using for debugging
1 parent 174db5b commit 3efdbfe

File tree

3 files changed

+10
-125
lines changed

3 files changed

+10
-125
lines changed

homeassistant/components/weatherflow_cloud/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
4848

4949
LOGGER.debug("Initializing WeatherFlowCloudDataUpdateCoordinatorREST coordinator")
5050

51-
# define initial data set:
52-
5351
rest_api = WeatherFlowRestAPI(
5452
api_token=entry.data[CONF_API_TOKEN], session=async_get_clientsession(hass)
5553
)

homeassistant/components/weatherflow_cloud/coordinator.py

+9-122
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@
3030
class BaseWeatherFlowCoordinator[T](DataUpdateCoordinator[dict[int, T]]):
3131
"""Base class for WeatherFlow coordinators."""
3232

33-
# Define static variables
34-
# _session: ClientSession
35-
# _ssl_context: SSLContext
36-
# _rest_api: WeatherFlowRestAPI
37-
# stations: StationsResponseREST | None = None
38-
# device_to_station_map: dict[int, int] = {}
39-
# device_ids: list[int] = []
40-
4133
def __init__(
4234
self,
4335
hass: HomeAssistant,
@@ -50,28 +42,12 @@ def __init__(
5042
self._token = rest_api.api_token
5143
self._rest_api = rest_api
5244
self.stations = stations
53-
LOGGER.error(f"🌮️ {self}")
54-
LOGGER.error(f"🌮️ {dir(stations)}")
55-
LOGGER.error(f"🌮️ {stations}")
56-
LOGGER.error(f"🌮️ {stations}")
5745
self.device_to_station_map = stations.device_station_map
5846

5947
self.device_ids = list(stations.device_station_map.keys())
6048

6149
self._ssl_context = client_context()
6250

63-
# # Use these variables as static
64-
# if not hasattr(BaseWeatherFlowCoordinator, "_session"):
65-
# BaseWeatherFlowCoordinator._session = async_get_clientsession(hass)
66-
# if not hasattr(BaseWeatherFlowCoordinator, "_ssl_context"):
67-
# BaseWeatherFlowCoordinator._ssl_context = client_context()
68-
#
69-
# # Initialize the API once
70-
# if not hasattr(BaseWeatherFlowCoordinator, "_rest_api"):
71-
# BaseWeatherFlowCoordinator._rest_api = WeatherFlowRestAPI(
72-
# api_token=self._token, session=BaseWeatherFlowCoordinator._session
73-
# )
74-
7551
super().__init__(
7652
hass,
7753
LOGGER,
@@ -130,7 +106,13 @@ class WeatherFlowCloudDataCallbackCoordinator[
130106
M: RapidWindListenStartMessage | ListenStartMessage,
131107
C: RapidWindWS | ObservationTempestWS,
132108
](BaseWeatherFlowCoordinator[dict[int, T | None]]):
133-
"""A Generic coordinator to handle Websocket connections."""
109+
"""A Generic coordinator to handle Websocket connections.
110+
111+
This class takes 3 generics - T, M, and C.
112+
T - The type of data that will be stored in the coordinator.
113+
M - The type of message that will be sent to the websocket API.
114+
C - The type of message that will be received from the websocket API.
115+
"""
134116

135117
def __init__(
136118
self,
@@ -149,7 +131,7 @@ def __init__(
149131
self.websocket_api = websocket_api
150132
self._listen_request_type = listen_request_type
151133

152-
# pre-initialize ws data
134+
# configure the websocket data structure
153135
self._ws_data: dict[int, dict[int, T | None]] = {
154136
station: {device: None for device in devices}
155137
for station, devices in self.stations.station_device_map.items()
@@ -162,7 +144,7 @@ async def _generic_callback(self, data: C):
162144
self.async_set_updated_data(self._ws_data)
163145

164146
async def _async_setup(self) -> None:
165-
LOGGER.error(f"Setup {self.__class__.__name__} with token: {self._token}")
147+
# Open the websocket connection
166148
await self.websocket_api.connect(self._ssl_context)
167149
# Register callback
168150
self.websocket_api._register_callback( # noqa:SLF001
@@ -174,7 +156,6 @@ async def _async_setup(self) -> None:
174156
await self.websocket_api.send_message(
175157
self._listen_request_type(device_id=str(device_id))
176158
)
177-
LOGGER.error(f"Sending listen request for {self.__class__.__name__}")
178159

179160
def get_station(self, station_id: int):
180161
"""Return station for id."""
@@ -185,97 +166,3 @@ def get_station_name(self, station_id: int) -> str:
185166
if name := self.stations.station_map[station_id].name:
186167
return name
187168
return ""
188-
189-
#
190-
# class WeatherFlowCloudDataUpdateCoordinatorObservation(
191-
# BaseWeatherFlowCoordinator[dict[int, WebsocketObservation]]
192-
# ):
193-
# """A Generic coordinator to handle Websocket connections."""
194-
#
195-
# def __init__(
196-
# self,
197-
# hass: HomeAssistant,
198-
# token: str,
199-
# stations: StationsResponseREST,
200-
# websocket_api: WeatherFlowWebsocketAPI,
201-
# ) -> None:
202-
# """Initialize Coordinator."""
203-
# super().__init__(hass=hass, token=token)
204-
# self.stations = stations
205-
# self.websocket_api = websocket_api
206-
#
207-
# self._ws_data: dict[int, dict[int, WebsocketObservation]] = {
208-
# station: {device: None for device in devices}
209-
# for station, devices in self.stations.station_device_map.items()
210-
# }
211-
#
212-
#
213-
#
214-
# async def _observation_callback(self, data: WebsocketObservation):
215-
# """Define callback for observation events."""
216-
# device_id = data.device_id
217-
# station_id = self.device_to_station_map[device_id]
218-
# self._ws_data[station_id][device_id] = data
219-
# LOGGER.debug(f"Updated Observation Data for: {station_id}:{device_id} = {data}")
220-
# self.async_set_updated_data(self._ws_data)
221-
#
222-
# # async def _async_setup(self) -> None:
223-
# # """Set up the coordinator."""
224-
# # LOGGER.debug(f"Setup {self.__class__.__name__} with token: {self.token}")
225-
# #
226-
#
227-
# async def _async_setup(self) -> None:
228-
# await self.api.connect(self._ssl_context)
229-
#
230-
# # Register callback
231-
# self.api.register_observation_callback(self._observation_callback)
232-
233-
234-
# # Subscribe to messages
235-
# for device_id in self.device_ids:
236-
# await self.api.send_message(ListenStartMessage(device_id=str(device_id)))
237-
#
238-
#
239-
# class WeatherFlowCloudDataCoordinatorWind(
240-
# BaseWeatherFlowCoordinator[dict[int, EventDataRapidWind]]
241-
# ):
242-
# """Websocket coordinator for wind."""
243-
#
244-
# def __init__(
245-
# self,
246-
# hass: HomeAssistant,
247-
# token: str,
248-
# # Optional Fields
249-
# stations: StationsResponseREST,
250-
# websocket_api: WeatherFlowWebsocketAPI,
251-
# ) -> None:
252-
# """Initialize Coordinator."""
253-
# super().__init__(hass=hass, token=token)
254-
#
255-
# self.stations = stations
256-
# self.websocket_api = websocket_api
257-
#
258-
# self._ws_data: dict[int, dict[int, EventDataRapidWind]] = {
259-
# station: {device: None for device in devices}
260-
# for station, devices in self.stations.station_device_map.items()
261-
# }
262-
#
263-
# async def _rapid_wind_callback(self, data: RapidWindWS):
264-
# """Define callback for wind events."""
265-
# device_id = data.device_id
266-
# station_id = self.device_to_station_map[device_id]
267-
# self._ws_data[station_id][device_id] = data.ob
268-
# LOGGER.debug(f"Updated Wind Data for: {station_id}:{device_id} = {data.ob}")
269-
# self.async_set_updated_data(self._ws_data)
270-
#
271-
# async def _async_setup(self) -> None:
272-
# # Connect the socket -> this is likely duplicate code we should fix
273-
# await self.api.connect(self._ssl_context)
274-
# # Register callback
275-
# self.api.register_wind_callback(self._rapid_wind_callback)
276-
# # Send listen Request
277-
# for device_id in self.device_ids:
278-
# await self.api.send_message(
279-
# RapidWindListenStartMessage(device_id=str(device_id))
280-
# )
281-
#

requirements_all.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2950,7 +2950,7 @@ watchdog==2.3.1
29502950
waterfurnace==1.1.0
29512951

29522952
# homeassistant.components.weatherflow_cloud
2953-
weatherflow4py==1.0.4
2953+
weatherflow4py==1.0.6
29542954

29552955
# homeassistant.components.webmin
29562956
webmin-xmlrpc==0.0.2

0 commit comments

Comments
 (0)