Skip to content

Commit

Permalink
Fix #70 and some other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
elad-bar committed Jun 30, 2020
1 parent 4b2d51f commit 326c8da
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 2020-06-30

**Fixed bugs:**

- Profile Switch [\#70](https://github.com/elad-bar/ha-bleuiris/issues/70) - Set lock=1 (Schedule=HOLD) when changing profile to lock the profile as set in switch

**Implemented enhancements:**

- Moved some of INFO log level messages into DEBUG for clearer debugging
- Added CircleCI support to build and run tests

## 2020-05-21

**Fixed bugs:**
Expand Down
22 changes: 19 additions & 3 deletions custom_components/blueiris/api/blue_iris_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def __init__(self, hass: HomeAssistant, config_manager: ConfigManager):
def is_initialized(self):
return self.session is not None and not self.session.closed

@property
def config_data(self):
return self.config_manager.data

async def async_verified_post(self, data):
result = None

Expand Down Expand Up @@ -103,7 +107,7 @@ async def initialize(self):
_LOGGER.info(f"Initializing BlueIris")

try:
config_data = self.config_manager.data
config_data = self.config_data

self.base_url = (
f"{config_data.protocol}://{config_data.host}:{config_data.port}"
Expand Down Expand Up @@ -134,6 +138,8 @@ async def initialize(self):
)

async def async_update(self):
_LOGGER.info(f"Updating data from BI Server ({self.config_data.name})")

await self.load_camera()
await self.load_status()

Expand Down Expand Up @@ -199,7 +205,7 @@ async def login(self):
return self.is_logged_in

async def load_camera(self):
_LOGGER.info(f"Retrieving camera list")
_LOGGER.debug(f"Retrieving camera list")

request_data = {"cmd": "camlist", "session": self.session_id}

Expand All @@ -209,7 +215,7 @@ async def load_camera(self):
self.camera_list = response.get("data", [])

async def load_status(self):
_LOGGER.info(f"Retrieving status")
_LOGGER.debug(f"Retrieving status")

request_data = {"cmd": "status", "session": self.session_id}

Expand All @@ -222,6 +228,9 @@ async def load_status(self):
self.status[key] = data[key]

async def set_profile(self, profile_id):
await self._set_profile(profile_id)

async def _set_profile(self, profile_id, check_lock=True):
_LOGGER.info(f"Setting profile (#{profile_id})")

request_data = {
Expand All @@ -235,5 +244,12 @@ async def set_profile(self, profile_id):
if response is not None:
data = response.get("data", {})

lock = data.get("lock")

if check_lock and lock != 1:
await self._set_profile(profile_id, False)

return

for key in data:
self.status[key] = data[key]
11 changes: 6 additions & 5 deletions custom_components/blueiris/binary_sensors/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,26 @@ def turn_off_automatically(now):
super()._immediate_update(previous_state)

else:
should_alert = False
should_alert = True

if self._last_alert is None:
message = "Identified first time"
should_alert = True
else:
time_since = current_timestamp - self._last_alert
message = f"{time_since} seconds ago"

if current_timestamp - self._last_alert > AUDIO_EVENT_LENGTH:
message = f"Identified {message}"
should_alert = True
else:
message = f"Irrelevant {message}"

_LOGGER.info(f"Audio alert on, {message} | {self.name}")
should_alert = False

if should_alert:
_LOGGER.info(f"Audio alert on, {message} | {self.name}")

self._last_alert = current_timestamp
super()._immediate_update(previous_state)

async_call_later(self.hass, 2, turn_off_automatically)
else:
_LOGGER.debug(f"Audio alert on, {message} | {self.name}")

0 comments on commit 326c8da

Please sign in to comment.