diff --git a/custom_components/frigate/__init__.py b/custom_components/frigate/__init__.py index 7c4de32e..7ed34fbe 100644 --- a/custom_components/frigate/__init__.py +++ b/custom_components/frigate/__init__.py @@ -164,6 +164,11 @@ def get_zones(config: dict[str, Any]) -> set[str]: return cameras_zones +def decode_if_necessary(data: str | bytes) -> str: + """Decode a string if necessary.""" + return data.decode("utf-8") if isinstance(data, bytes) else data + + async def async_setup(hass: HomeAssistant, config: Config) -> bool: """Set up this integration using YAML is not supported.""" integration = await async_get_integration(hass, DOMAIN) @@ -474,5 +479,5 @@ async def async_will_remove_from_hass(self) -> None: @callback # type: ignore[misc] def _availability_message_received(self, msg: ReceiveMessage) -> None: """Handle a new received MQTT availability message.""" - self._available = msg.payload == "online" + self._available = decode_if_necessary(msg.payload) == "online" self.async_write_ha_state() diff --git a/custom_components/frigate/binary_sensor.py b/custom_components/frigate/binary_sensor.py index 260f4815..e7325c85 100644 --- a/custom_components/frigate/binary_sensor.py +++ b/custom_components/frigate/binary_sensor.py @@ -16,6 +16,7 @@ from . import ( FrigateMQTTEntity, ReceiveMessage, + decode_if_necessary, get_cameras, get_cameras_and_audio, get_cameras_zones_and_objects, @@ -184,7 +185,7 @@ def __init__( @callback # type: ignore[misc] def _state_message_received(self, msg: ReceiveMessage) -> None: """Handle a new received MQTT state message.""" - self._is_on = msg.payload == "ON" + self._is_on = decode_if_necessary(msg.payload) == "ON" self.async_write_ha_state() @property @@ -265,7 +266,7 @@ def __init__( @callback # type: ignore[misc] def _state_message_received(self, msg: ReceiveMessage) -> None: """Handle a new received MQTT state message.""" - self._is_on = msg.payload == "ON" + self._is_on = decode_if_necessary(msg.payload) == "ON" self.async_write_ha_state() @property diff --git a/custom_components/frigate/camera.py b/custom_components/frigate/camera.py index f660b098..cd8c6b39 100644 --- a/custom_components/frigate/camera.py +++ b/custom_components/frigate/camera.py @@ -27,6 +27,7 @@ FrigateEntity, FrigateMQTTEntity, ReceiveMessage, + decode_if_necessary, get_friendly_name, get_frigate_device_identifier, get_frigate_entity_unique_id, @@ -238,13 +239,13 @@ def __init__( @callback # type: ignore[misc] def _state_message_received(self, msg: ReceiveMessage) -> None: """Handle a new received MQTT state message.""" - self._attr_is_recording = msg.payload.decode("utf-8") == "ON" + self._attr_is_recording = decode_if_necessary(msg.payload) == "ON" self.async_write_ha_state() @callback # type: ignore[misc] def _motion_message_received(self, msg: ReceiveMessage) -> None: """Handle a new received MQTT extra message.""" - self._attr_motion_detection_enabled = msg.payload.decode("utf-8") == "ON" + self._attr_motion_detection_enabled = decode_if_necessary(msg.payload) == "ON" self.async_write_ha_state() @property diff --git a/custom_components/frigate/manifest.json b/custom_components/frigate/manifest.json index 466e5562..60119bbb 100644 --- a/custom_components/frigate/manifest.json +++ b/custom_components/frigate/manifest.json @@ -14,5 +14,5 @@ "iot_class": "local_push", "issue_tracker": "https://github.com/blakeblackshear/frigate-hass-integration/issues", "requirements": ["pytz"], - "version": "5.1.0" + "version": "5.2.0" } diff --git a/custom_components/frigate/switch.py b/custom_components/frigate/switch.py index e8d43944..e724bfd8 100644 --- a/custom_components/frigate/switch.py +++ b/custom_components/frigate/switch.py @@ -15,6 +15,7 @@ from . import ( FrigateMQTTEntity, ReceiveMessage, + decode_if_necessary, get_friendly_name, get_frigate_device_identifier, get_frigate_entity_unique_id, @@ -119,7 +120,7 @@ def __init__( @callback # type: ignore[misc] def _state_message_received(self, msg: ReceiveMessage) -> None: """Handle a new received MQTT state message.""" - self._is_on = msg.payload == "ON" + self._is_on = decode_if_necessary(msg.payload) == "ON" self.async_write_ha_state() @property diff --git a/custom_components/frigate/translations/ca.json b/custom_components/frigate/translations/ca.json new file mode 100644 index 00000000..2863a47b --- /dev/null +++ b/custom_components/frigate/translations/ca.json @@ -0,0 +1,36 @@ +{ + "config": { + "step": { + "user": { + "description": "L'URL que utilitzeu per accedir a Frigate (p. ex. 'http://frigate:5000/')\\n\\nSi feu servir HassOS amb el complement, l'URL hauria de ser 'http://ccab4aaf-frigate:5000/' \\n\\nHome Assistant necessita accedir al port 5000 (api) i 1935 (rtmp) per a totes les funcions.\\n\\nLa integració configurarà sensors, càmeres i la funcionalitat del navegador multimèdia.\\n\\nSensors:\\n- Estadístiques per supervisar el rendiment de Frigate\\n- Recompte d'objectes per a totes les zones i càmeres\\n\\nCàmeres:\\n- Càmeres per a la imatge de l'últim objecte detectat per a cada càmera\\n- Entitats de càmera amb suport de transmissió (requereix RTMP)\\n\\nNavegador multimèdia:\\n - Interfície d'usuari enriquida amb miniatures per explorar clips d'esdeveniments\\n- Interfície d'usuari enriquida per navegar per enregistraments les 24 hores al dia, els set dies a la setmana, per mes, dia, càmera, hora\\n\\nAPI:\\n- API de notificació amb punts de connexió públics per a imatges a les notificacions.", + "data": { + "url": "URL" + } + } + }, + "error": { + "cannot_connect": "No s'ha pogut connectar", + "invalid_url": "URL no vàlid" + }, + "abort": { + "already_configured": "El dispositiu ja està configurat" + } + }, + "options": { + "step": { + "init": { + "data": { + "enable_webrtc": "Activa WebRTC per als fluxos de la càmera", + "rtmp_url_template": "Plantilla de l'URL del RTMP (vegeu la documentació)", + "rtsp_url_template": "Plantilla de l'URL del RTSP (vegeu la documentació)", + "media_browser_enable": "Habiliteu el navegador multimèdia", + "notification_proxy_enable": "Habiliteu el servidor intermediari no autenticat d'esdeveniments de notificacions", + "notification_proxy_expire_after_seconds": "No permetre l'accés a notificacions no autenticades després dels segons especificats (0=mai)" + } + } + }, + "abort": { + "only_advanced_options": "El mode avançat està desactivat i només hi ha opcions avançades" + } + } +} \ No newline at end of file diff --git a/tests/test_switch.py b/tests/test_switch.py index f4e70a90..7ed7c7b9 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -87,6 +87,18 @@ async def test_switch_state(hass: HomeAssistant) -> None: assert entity_state assert entity_state.state == "off" + async_fire_mqtt_message(hass, "frigate/front_door/detect/state", b"ON") + await hass.async_block_till_done() + entity_state = hass.states.get(TEST_SWITCH_FRONT_DOOR_DETECT_ENTITY_ID) + assert entity_state + assert entity_state.state == "on" + + async_fire_mqtt_message(hass, "frigate/front_door/detect/state", b"OFF") + await hass.async_block_till_done() + entity_state = hass.states.get(TEST_SWITCH_FRONT_DOOR_DETECT_ENTITY_ID) + assert entity_state + assert entity_state.state == "off" + async_fire_mqtt_message(hass, "frigate/front_door/detect/state", "INVALID_VALUE") await hass.async_block_till_done() entity_state = hass.states.get(TEST_SWITCH_FRONT_DOOR_DETECT_ENTITY_ID)