Skip to content

Commit

Permalink
Merge pull request #673 from blakeblackshear/dev
Browse files Browse the repository at this point in the history
Merged `dev` back into `master`
  • Loading branch information
dermotduffy authored May 4, 2024
2 parents 52bb8ad + 4b7b240 commit 5b9f4f7
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 7 deletions.
7 changes: 6 additions & 1 deletion custom_components/frigate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
5 changes: 3 additions & 2 deletions custom_components/frigate/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from . import (
FrigateMQTTEntity,
ReceiveMessage,
decode_if_necessary,
get_cameras,
get_cameras_and_audio,
get_cameras_zones_and_objects,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions custom_components/frigate/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
FrigateEntity,
FrigateMQTTEntity,
ReceiveMessage,
decode_if_necessary,
get_friendly_name,
get_frigate_device_identifier,
get_frigate_entity_unique_id,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/frigate/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion custom_components/frigate/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from . import (
FrigateMQTTEntity,
ReceiveMessage,
decode_if_necessary,
get_friendly_name,
get_frigate_device_identifier,
get_frigate_entity_unique_id,
Expand Down Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions custom_components/frigate/translations/ca.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
12 changes: 12 additions & 0 deletions tests/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5b9f4f7

Please sign in to comment.