Skip to content

Commit

Permalink
fix: missing on_error callback function on setup
Browse files Browse the repository at this point in the history
  • Loading branch information
fuatakgun committed Aug 1, 2023
1 parent 3edb2f2 commit 8047ecd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ Welcome to Alpha release of Eufy Security Integration for Home Assistant. Congra

- [Gratitude](#gratitude)
- [How is this working?](#how-is-this-working)
- [RTSP Based Streaming - When your devices support RTSP](#rtsp-based-streaming---when-your-devices-support-rtsp)
- [Supported or Known Working devices](#supported-or-known-working-devices)
- [Installation](#installation)
- [Important: You must set Streaming Quality to LOW and Streaming Codec to LOW in all possible places, otherwise Home Assistant will not be able to handle video generation and/or playing.](#important-you-must-set-streaming-quality-to-low-and-streaming-codec-to-low-in-all-possible-places-otherwise-home-assistant-will-not-be-able-to-handle-video-generation-andor-playing)
- [1. Installing Eufy Security Add-On](#1-installing-eufy-security-add-on)
- [2. Install RTSP Simple Server Add-on - Required for P2P Based Video Streaming - Not Required for RTSP Based Video Streaming](#2-install-rtsp-simple-server-add-on---required-for-p2p-based-video-streaming---not-required-for-rtsp-based-video-streaming)
- [3. Installing Eufy Security Integration](#3-installing-eufy-security-integration)
Expand All @@ -24,14 +26,46 @@ Welcome to Alpha release of Eufy Security Integration for Home Assistant. Congra

# How is this working?

- @bropat built `eufy-security-ws` using `eufy-security-client` to imitate mobile app and web portal functionalities and I had wrapped `eufy-security-ws` as `eufy_security_addon` so we can use it as Home Assistant Add-on.
- @bropat built `eufy-security-ws` using `eufy-security-client` to imitate mobile app and web portal functionalities and wrapped `eufy-security-ws` as `hassio-eufy-security-ws` so we can use it as Home Assistant Add-on.
- Add-on requires email address, password, country code, event duration in seconds and trusted device name.
- Every time add-on is started, it forces all other sessions to log off, so you must create a secondary account and share your home/devices with secondary account including admin rights and you must use secondary account credentials on add-on page. Please login once to eufy mobile app with this secondary account to be sure that devices are available.
- Country code is very crucial to connect to correct regional servers. If your main account has setup in US and if you are trying to login into your secondary account in DE country, your device data would not be found in EU servers. So please pay attention to put correct country code. (Source: Alpha 2 country code https://en.wikipedia.org/wiki/ISO_3166-1#Officially_assigned_code_elements)
- Event duration in seconds correspond to how long (in seconds) entities in home assistant would stay in active. As an example, when camera notices a person, add-on would receive a push notification from eufy and home assistant integration will active person detected sensor and person detected sensor will stay on state for `event duration in seconds` long.
- Trusted device name is a required identifier for eufy systems to record this add-on as mobile client, so you can differentiate the connection from this add-on in multi factor authentication (two factor authentication) page.
- As we already called out earlier, add-on heavily relies on push notifications, so you must enable all kind of push notifications (motion detected, person detected, lock events, alarm events etc) in your mobile app. These notifications are not user based but device based so after enabling all these notifications, your main account will probably bloated with many push notifications. In android, there is a setting to disable specific notifications, please use it.

## RTSP Based Streaming - When your devices support RTSP

```mermaid
sequenceDiagram
Home Assistant ->> Eufy-Security-WS: Call Start RTSP Stream
Eufy-Security-WS ->> Device/Station: Call Start RTSP Stream
Device/Station ->> Eufy-Security-WS: Return RTSP Stream URL
Eufy-Security-WS ->> Home Assistant: Return RTSP Stream URL
Home Assistant ->> Device/Station: (Native) Watch Video
WebRTC (go2rtc) ->> Device/Station: Get RTSP Stream Bytes
WebRTC (go2rtc) ->> WebRTC (go2rtc): Generate WebRTC Video
Home Assistant ->> WebRTC (go2rtc): (WebRTC) Watch Video
```

P2P Based Streaming - When we have to generate the stream in hard way

```mermaid
sequenceDiagram
Home Assistant ->> Eufy-Security-WS: Call Start Live Stream
Eufy-Security-WS ->> Device/Station: Call Start Live Stream
Device/Station ->> Eufy-Security-WS: Return data bytes from stream
Eufy-Security-WS ->> Home Assistant: Return data bytes from stream
Home Assistant ->> Random TCP Port: Write data bytes from stream
Random TCP Port ->> FFMPEG Process : Write individiual bytes of stream
FFMPEG Process ->> RTSP Simple Server: Generate Video Stream via codec
RTSP Simple Server ->> RTSP Simple Server: Generate RTSP Stream (rtsp://127.0.0.1:9554/SERIALNO)
Home Assistant ->> RTSP Simple Server: (Native) Watch Video
WebRTC (go2rtc) ->> RTSP Simple Server: Get RTSP Stream Bytes
WebRTC (go2rtc) ->> WebRTC (go2rtc): Generate WebRTC Video
Home Assistant ->> WebRTC (go2rtc): (WebRTC) Watch Video
```

# Supported or Known Working devices

Please check here: /~https://github.com/bropat/eufy-security-client#known-working-devices
Expand All @@ -50,6 +84,8 @@ If you are intending to use this integration for video streaming purposes and if

Lastly, your camera would not start streaming magically by itself, you have to call `turn_on` or `turn_off` services of respective camera entities. So, when you first install everything, you would not have any video until you call these functions. Moreover, P2P streaming might stop randomly because of low level issues, you can restart it again with `turn_off` and `turn_on`. You can trigger your automations on camera states (idle, preparing, streaming).

### Important: You must set Streaming Quality to LOW and Streaming Codec to LOW in all possible places, otherwise Home Assistant will not be able to handle video generation and/or playing. ###

So, let's start.

## 1. Installing Eufy Security Add-On
Expand Down
2 changes: 1 addition & 1 deletion custom_components/eufy_security/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def _show_config_form(self, user_input): # pylint: disable=unused-argumen
async def _test_credentials(self, host, port): # pylint: disable=unused-argument
try:
config = Config(host=host, port=port)
api_client: ApiClient = ApiClient(config, aiohttp_client.async_get_clientsession(self.hass))
api_client: ApiClient = ApiClient(config, aiohttp_client.async_get_clientsession(self.hass), None)
await api_client.ws_connect()
await api_client.disconnect()
return True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def connect(self):
try:
self.socket = await self.session.ws_connect(f"ws://{self.host}:{self.port}", autoclose=False, autoping=True, heartbeat=60)
except Exception as exc:
raise WebSocketConnectionException() from exc
raise WebSocketConnectionException("Connection to add-on was broken. please reload the integration!") from exc
self.task = self.loop.create_task(self._process_messages())
self.task.add_done_callback(self._on_close)
await self._on_open()
Expand Down

0 comments on commit 8047ecd

Please sign in to comment.