Prepare data structures for rain graph

This commit is contained in:
Jules 2023-12-31 23:36:57 +01:00
parent 77653976cf
commit 27fab148b6
Signed by: jdejaegh
GPG key ID: 99D6D184CA66933A
4 changed files with 17 additions and 10 deletions

View file

@ -194,15 +194,14 @@ class IrmKmiCoordinator(DataUpdateCoordinator):
)
if most_recent_frame is None and current_time < time_image:
recent_idx = idx - 1 if idx > 0 else idx
most_recent_frame = sequence[recent_idx].get('image', None)
most_recent_frame = idx - 1 if idx > 0 else idx
background.close()
most_recent_frame = most_recent_frame if most_recent_frame is not None else sequence[-1].get('image')
most_recent_frame = most_recent_frame if most_recent_frame is not None else -1
return RadarAnimationData(
sequence=sequence,
most_recent_image=most_recent_frame
most_recent_image_idx=most_recent_frame
)
@staticmethod

View file

@ -28,13 +28,19 @@ class AnimationFrameData(TypedDict, total=False):
"""Holds one single frame of the radar camera, along with the timestamp of the frame"""
time: datetime | None
image: bytes | None
value: float | None
position: float | None
position_higher: float | None
position_lower: float | None
rain_graph: bytes | None
class RadarAnimationData(TypedDict, total=False):
"""Holds frames and additional data for the animation to be rendered"""
sequence: List[AnimationFrameData] | None
most_recent_image: bytes | None
most_recent_image_idx: int | None
hint: str | None
unit: str | None
class ProcessedCoordinatorData(TypedDict, total=False):

View file

@ -4,3 +4,5 @@ homeassistant==2023.12.3
voluptuous==0.13.1
Pillow==10.1.0
pytz==2023.3.post1
svgwrite==1.4.3
CairoSVG==2.7.1

View file

@ -135,8 +135,8 @@ async def test_get_image_nl(
result_image = Image.open(BytesIO(result['sequence'][-1]['image'])).convert('RGBA')
assert list(result_image.getdata()) == list(expected.getdata())
thumb_image = Image.open(BytesIO(result['most_recent_image'])).convert('RGBA')
most_recent_image = result['sequence'][result['most_recent_image_idx']]['image']
thumb_image = Image.open(BytesIO(most_recent_image)).convert('RGBA')
assert list(thumb_image.getdata()) == list(expected.getdata())
assert result['hint'] == "No rain forecasted shortly"
@ -170,8 +170,8 @@ async def test_get_image_be(
result_image = Image.open(BytesIO(result['sequence'][9]['image'])).convert('RGBA')
assert list(result_image.getdata()) == list(expected.getdata())
thumb_image = Image.open(BytesIO(result['most_recent_image'])).convert('RGBA')
most_recent_image = result['sequence'][result['most_recent_image_idx']]['image']
thumb_image = Image.open(BytesIO(most_recent_image)).convert('RGBA')
assert list(thumb_image.getdata()) == list(expected.getdata())
assert result['hint'] == "No rain forecasted shortly"