Skip to content

Commit 3804c1a

Browse files
authored
Merge pull request #14 from jdejaegh/13-font-not-found
Try to fix font file not found issue
2 parents 16f40cf + 23f6900 commit 3804c1a

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

custom_components/irm_kmi/font_fallback.py

Lines changed: 6 additions & 0 deletions
Large diffs are not rendered by default.

custom_components/irm_kmi/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
"pytz==2023.3.post1",
1313
"svgwrite==1.4.3"
1414
],
15-
"version": "0.2.3"
15+
"version": "0.2.4"
1616
}

custom_components/irm_kmi/rain_graph.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import base64
44
import copy
5+
import logging
56
from typing import List
67

78
import pytz
@@ -10,7 +11,9 @@
1011

1112
from custom_components.irm_kmi.data import (AnimationFrameData,
1213
RadarAnimationData)
14+
from custom_components.irm_kmi.font_fallback import font_data
1315

16+
_LOGGER = logging.getLogger(__name__)
1417

1518
class RainGraph:
1619
def __init__(self,
@@ -85,7 +88,13 @@ def __init__(self,
8588

8689
def draw_svg_frame(self):
8790
"""Create the global area to draw the other items"""
88-
self._dwg.embed_font(name="Roboto Medium", filename='custom_components/irm_kmi/resources/roboto_medium.ttf')
91+
try:
92+
self._dwg.embed_font(name="Roboto Medium", filename='custom_components/irm_kmi/resources/roboto_medium.ttf')
93+
except FileNotFoundError as err:
94+
# Workaround for some cases where the font file cannot be opened. The font_data contains the strings
95+
# that must be embedded as a stylesheet for the roboto_medium.ttf font
96+
_LOGGER.warning(f'Could not find font {err}. Loading it using the fallback file.')
97+
self._dwg.embed_stylesheet(font_data)
8998
self._dwg.embed_stylesheet("""
9099
.roboto {
91100
font-family: "Roboto Medium";

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
aiohttp==3.9.3
22
async_timeout==4.0.3
3-
homeassistant==2024.2.1
3+
homeassistant==2024.3.3
44
voluptuous==0.13.1
55
pytz==2023.3.post1
66
svgwrite==1.4.3

requirements_tests.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
homeassistant==2024.2.1
1+
homeassistant==2024.3.3
22
pytest
3-
pytest_homeassistant_custom_component==0.13.100
3+
pytest_homeassistant_custom_component==0.13.109
44
freezegun
55
isort

0 commit comments

Comments
 (0)