mirror of
https://github.com/jdejaegh/irm-kmi-ha.git
synced 2025-06-27 11:39:26 +02:00
Prepare data structures for rain graph
This commit is contained in:
parent
77653976cf
commit
27fab148b6
4 changed files with 17 additions and 10 deletions
|
@ -194,15 +194,14 @@ class IrmKmiCoordinator(DataUpdateCoordinator):
|
||||||
)
|
)
|
||||||
|
|
||||||
if most_recent_frame is None and current_time < time_image:
|
if most_recent_frame is None and current_time < time_image:
|
||||||
recent_idx = idx - 1 if idx > 0 else idx
|
most_recent_frame = idx - 1 if idx > 0 else idx
|
||||||
most_recent_frame = sequence[recent_idx].get('image', None)
|
|
||||||
|
|
||||||
background.close()
|
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(
|
return RadarAnimationData(
|
||||||
sequence=sequence,
|
sequence=sequence,
|
||||||
most_recent_image=most_recent_frame
|
most_recent_image_idx=most_recent_frame
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -28,13 +28,19 @@ class AnimationFrameData(TypedDict, total=False):
|
||||||
"""Holds one single frame of the radar camera, along with the timestamp of the frame"""
|
"""Holds one single frame of the radar camera, along with the timestamp of the frame"""
|
||||||
time: datetime | None
|
time: datetime | None
|
||||||
image: bytes | 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):
|
class RadarAnimationData(TypedDict, total=False):
|
||||||
"""Holds frames and additional data for the animation to be rendered"""
|
"""Holds frames and additional data for the animation to be rendered"""
|
||||||
sequence: List[AnimationFrameData] | None
|
sequence: List[AnimationFrameData] | None
|
||||||
most_recent_image: bytes | None
|
most_recent_image_idx: int | None
|
||||||
hint: str | None
|
hint: str | None
|
||||||
|
unit: str | None
|
||||||
|
|
||||||
|
|
||||||
class ProcessedCoordinatorData(TypedDict, total=False):
|
class ProcessedCoordinatorData(TypedDict, total=False):
|
||||||
|
|
|
@ -4,3 +4,5 @@ homeassistant==2023.12.3
|
||||||
voluptuous==0.13.1
|
voluptuous==0.13.1
|
||||||
Pillow==10.1.0
|
Pillow==10.1.0
|
||||||
pytz==2023.3.post1
|
pytz==2023.3.post1
|
||||||
|
svgwrite==1.4.3
|
||||||
|
CairoSVG==2.7.1
|
|
@ -135,8 +135,8 @@ async def test_get_image_nl(
|
||||||
result_image = Image.open(BytesIO(result['sequence'][-1]['image'])).convert('RGBA')
|
result_image = Image.open(BytesIO(result['sequence'][-1]['image'])).convert('RGBA')
|
||||||
|
|
||||||
assert list(result_image.getdata()) == list(expected.getdata())
|
assert list(result_image.getdata()) == list(expected.getdata())
|
||||||
|
most_recent_image = result['sequence'][result['most_recent_image_idx']]['image']
|
||||||
thumb_image = Image.open(BytesIO(result['most_recent_image'])).convert('RGBA')
|
thumb_image = Image.open(BytesIO(most_recent_image)).convert('RGBA')
|
||||||
assert list(thumb_image.getdata()) == list(expected.getdata())
|
assert list(thumb_image.getdata()) == list(expected.getdata())
|
||||||
|
|
||||||
assert result['hint'] == "No rain forecasted shortly"
|
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')
|
result_image = Image.open(BytesIO(result['sequence'][9]['image'])).convert('RGBA')
|
||||||
|
|
||||||
assert list(result_image.getdata()) == list(expected.getdata())
|
assert list(result_image.getdata()) == list(expected.getdata())
|
||||||
|
most_recent_image = result['sequence'][result['most_recent_image_idx']]['image']
|
||||||
thumb_image = Image.open(BytesIO(result['most_recent_image'])).convert('RGBA')
|
thumb_image = Image.open(BytesIO(most_recent_image)).convert('RGBA')
|
||||||
assert list(thumb_image.getdata()) == list(expected.getdata())
|
assert list(thumb_image.getdata()) == list(expected.getdata())
|
||||||
|
|
||||||
assert result['hint'] == "No rain forecasted shortly"
|
assert result['hint'] == "No rain forecasted shortly"
|
||||||
|
|
Loading…
Add table
Reference in a new issue