1 """FRITZ image integration."""
3 from __future__
import annotations
8 from requests.exceptions
import RequestException
17 from .const
import DOMAIN
18 from .coordinator
import AvmWrapper
19 from .entity
import FritzBoxBaseEntity
21 _LOGGER = logging.getLogger(__name__)
27 async_add_entities: AddEntitiesCallback,
29 """Set up guest WiFi QR code for device."""
30 avm_wrapper: AvmWrapper = hass.data[DOMAIN][entry.entry_id]
32 guest_wifi_info = await hass.async_add_executor_job(
33 avm_wrapper.fritz_guest_wifi.get_info
39 hass, avm_wrapper, entry.title, guest_wifi_info[
"NewSSID"]
46 """Implementation of the FritzBox guest wifi QR code image entity."""
48 _attr_content_type =
"image/png"
49 _attr_entity_category = EntityCategory.DIAGNOSTIC
50 _attr_has_entity_name =
True
51 _attr_should_poll =
True
56 avm_wrapper: AvmWrapper,
57 device_friendly_name: str,
60 """Initialize the image entity."""
64 super().
__init__(avm_wrapper, device_friendly_name)
65 ImageEntity.__init__(self, hass)
68 """Fetch the QR code from the Fritz!Box."""
69 qr_stream: BytesIO = await self.
hasshass.async_add_executor_job(
70 self.
_avm_wrapper_avm_wrapper.fritz_guest_wifi.get_wifi_qr_code,
"png"
72 qr_bytes = qr_stream.getvalue()
73 _LOGGER.debug(
"fetched %s bytes", len(qr_bytes))
78 """Fetch and set initial data and state."""
83 """Update the image entity data."""
86 except RequestException:
93 dt_now = dt_util.utcnow()
94 _LOGGER.debug(
"qr code has changed, reset image last updated property")
100 """Return bytes of image."""
None __init__(self, HomeAssistant hass, AvmWrapper avm_wrapper, str device_friendly_name, str ssid)
None async_added_to_hass(self)
bytes|None async_image(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)