Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion custom_components/qr_generator/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
25 changes: 24 additions & 1 deletion tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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: ą, ę, ń"