mirror of
https://github.com/jdejaegh/irm-kmi-ha.git
synced 2025-06-27 11:39:26 +02:00
Refactor and add docstring
This commit is contained in:
parent
758eac09c2
commit
0eb96a63bf
5 changed files with 14 additions and 8 deletions
|
@ -51,7 +51,6 @@ class IrmKmiApiClient:
|
||||||
|
|
||||||
async def get_image(self, url, params: dict | None = None) -> bytes:
|
async def get_image(self, url, params: dict | None = None) -> bytes:
|
||||||
"""Get the image at the specified url with the parameters"""
|
"""Get the image at the specified url with the parameters"""
|
||||||
# TODO support etag and head request before requesting content
|
|
||||||
r: ClientResponse = await self._api_wrapper(base_url=url, params={} if params is None else params)
|
r: ClientResponse = await self._api_wrapper(base_url=url, params={} if params is None else params)
|
||||||
return await r.read()
|
return await r.read()
|
||||||
|
|
||||||
|
|
|
@ -301,7 +301,7 @@ class IrmKmiCoordinator(DataUpdateCoordinator):
|
||||||
country: str,
|
country: str,
|
||||||
images_from_api: Tuple[bytes],
|
images_from_api: Tuple[bytes],
|
||||||
) -> RainGraph:
|
) -> RainGraph:
|
||||||
|
"""Create a RainGraph object that is ready to output animated and still SVG images"""
|
||||||
sequence: List[AnimationFrameData] = list()
|
sequence: List[AnimationFrameData] = list()
|
||||||
tz = pytz.timezone(self.hass.config.time_zone)
|
tz = pytz.timezone(self.hass.config.time_zone)
|
||||||
current_time = datetime.now(tz=tz)
|
current_time = datetime.now(tz=tz)
|
||||||
|
|
|
@ -135,6 +135,7 @@ class RainGraph:
|
||||||
self.write_time_and_rain(paragraph, rain_level, time)
|
self.write_time_and_rain(paragraph, rain_level, time)
|
||||||
|
|
||||||
def write_time_and_rain(self, paragraph, rain_level, time):
|
def write_time_and_rain(self, paragraph, rain_level, time):
|
||||||
|
"""Using the paragraph object, write the time and rain level data"""
|
||||||
paragraph.add(self._dwg.text(f"{time}", insert=(self._offset, self._top_text_y_pos),
|
paragraph.add(self._dwg.text(f"{time}", insert=(self._offset, self._top_text_y_pos),
|
||||||
text_anchor="start",
|
text_anchor="start",
|
||||||
font_size="16px",
|
font_size="16px",
|
||||||
|
@ -186,6 +187,7 @@ class RainGraph:
|
||||||
self.draw_chance_precip(list_higher_points, list_lower_points)
|
self.draw_chance_precip(list_higher_points, list_lower_points)
|
||||||
|
|
||||||
def draw_chance_precip(self, list_higher_points: List, list_lower_points: List):
|
def draw_chance_precip(self, list_higher_points: List, list_lower_points: List):
|
||||||
|
"""Draw the blue solid line representing the actual rain forecast"""
|
||||||
precip_higher_chance_path = self._dwg.path(fill='#63c8fa', stroke='none', opacity=.3)
|
precip_higher_chance_path = self._dwg.path(fill='#63c8fa', stroke='none', opacity=.3)
|
||||||
|
|
||||||
list_higher_points[-1] = tuple(list(list_higher_points[-1]) + ['last'])
|
list_higher_points[-1] = tuple(list(list_higher_points[-1]) + ['last'])
|
||||||
|
|
|
@ -44,5 +44,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"issues": {
|
||||||
|
"zone_moved": {
|
||||||
|
"title": "Zone moved",
|
||||||
|
"description": "Hey!"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,19 +9,18 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def disable_from_config(hass: HomeAssistant, config_entry: ConfigEntry):
|
def disable_from_config(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||||
modify_from_config(hass, config_entry, False)
|
modify_from_config(hass, config_entry.entry_id, False)
|
||||||
|
|
||||||
|
|
||||||
def enable_from_config(hass: HomeAssistant, config_entry: ConfigEntry):
|
def enable_from_config(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||||
modify_from_config(hass, config_entry, True)
|
modify_from_config(hass, config_entry.entry_id, True)
|
||||||
|
|
||||||
|
|
||||||
def modify_from_config(hass: HomeAssistant, config_entry: ConfigEntry, enable: bool):
|
def modify_from_config(hass: HomeAssistant, config_entry_id: str, enable: bool):
|
||||||
dr = device_registry.async_get(hass)
|
dr = device_registry.async_get(hass)
|
||||||
devices = device_registry.async_entries_for_config_entry(dr, config_entry.entry_id)
|
devices = device_registry.async_entries_for_config_entry(dr, config_entry_id)
|
||||||
_LOGGER.info(f"Trying to {'enable' if enable else 'disable'} {config_entry.entry_id}: {len(devices)} device(s)")
|
_LOGGER.info(f"Trying to {'enable' if enable else 'disable'} {config_entry_id}: {len(devices)} device(s)")
|
||||||
for device in devices:
|
for device in devices:
|
||||||
_LOGGER.info(f"Disabling device {device.name} because it is out of Benelux")
|
|
||||||
dr.async_update_device(device_id=device.id,
|
dr.async_update_device(device_id=device.id,
|
||||||
disabled_by=None if enable else device_registry.DeviceEntryDisabler.INTEGRATION)
|
disabled_by=None if enable else device_registry.DeviceEntryDisabler.INTEGRATION)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue