Skip to content

Commit

Permalink
Prepare data structures for rain graph
Browse files Browse the repository at this point in the history
  • Loading branch information
jdejaegh committed Dec 31, 2023
1 parent 7765397 commit 27fab14
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
7 changes: 3 additions & 4 deletions custom_components/irm_kmi/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,14 @@ async def merge_frames_from_api(self,
)

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
Expand Down
8 changes: 7 additions & 1 deletion custom_components/irm_kmi/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ async_timeout==4.0.3
homeassistant==2023.12.3
voluptuous==0.13.1
Pillow==10.1.0
pytz==2023.3.post1
pytz==2023.3.post1
svgwrite==1.4.3
CairoSVG==2.7.1
8 changes: 4 additions & 4 deletions tests/test_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

0 comments on commit 27fab14

Please sign in to comment.