diff --git a/custom_components/qr_generator/image.py b/custom_components/qr_generator/image.py index e35e9f0..a1c2d00 100644 --- a/custom_components/qr_generator/image.py +++ b/custom_components/qr_generator/image.py @@ -122,7 +122,7 @@ async def _refresh(self) -> None: _LOGGER.debug('Print "%s" with: %s', self.name, self.rendered_template.result()) code = pyqrcode.create( - self.rendered_template.result(), error=self.error_correction + self.rendered_template.result(), error=self.error_correction, encoding='utf-8' ) self.image = io.BytesIO() diff --git a/tests/test_image.py b/tests/test_image.py index 349ccaf..b21b918 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -42,11 +42,16 @@ CONF_BACKGROUND_COLOR: DEFAULT_BACKGROUND_COLOR, } +DUMMY_ENTRY_UTF8 = { + **DUMMY_ENTRY, + CONF_VALUE_TEMPLATE: "Utf8: ą, ę, ń" +} + @pytest.mark.asyncio async def test_image(hass: HomeAssistant) -> None: """Test the creation and values of the image.""" config_entry: MockConfigEntry = MockConfigEntry( - domain=DOMAIN, title="NINA", data=DUMMY_ENTRY + domain=DOMAIN, title="QR", data=DUMMY_ENTRY ) entity_registry: er = er.async_get(hass) @@ -68,3 +73,21 @@ async def test_image(hass: HomeAssistant) -> None: assert state.attributes.get(ATTR_BACKGROUND_COLOR) == DEFAULT_BACKGROUND_COLOR assert entry.unique_id == f"{config_entry.entry_id}-qr-code" + +@pytest.mark.asyncio +async def test_support_utf8_chars(hass: HomeAssistant) -> None: + """Test if utf-8 chars are supported.""" + config_entry: MockConfigEntry = MockConfigEntry( + domain=DOMAIN, title="QR", data=DUMMY_ENTRY_UTF8 + ) + + config_entry.add_to_hass(hass) + + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + + assert config_entry.state == ConfigEntryState.LOADED + + state = hass.states.get("image.test_qr_code") + + assert state.attributes.get(ATTR_TEXT) == "Utf8: ą, ę, ń"