Skip to content

Commit

Permalink
Merge pull request #154 from kramttocs/fix-for-1.0.11
Browse files Browse the repository at this point in the history
Fix for missing camera models/types introduced in 1.0.11
Cleaned up some redundant calls to get Camera and System Device names
Added exception handling when setting the log level
  • Loading branch information
kramttocs authored Mar 7, 2022
2 parents 2202874 + 8d6ef55 commit 8757b30
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 29 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.0.12

- Fix for missing camera models/types introduced in 1.0.11
- Cleaned up some redundant calls to get Camera and System Device names
- Added exception handling when setting the log level

## 1.0.11

- !NOTE! This update impacts the name of the integration instance. It was always supposed to default to the Server name as specified in the Blue Iris server options. It does now. This should only take effect if you remove and re-add the integration.
Expand Down
9 changes: 8 additions & 1 deletion custom_components/blueiris/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ async def handle_log_level(hass: HomeAssistant, entry: ConfigEntry):

log_level_data = {f"custom_components.{DOMAIN}": log_level.lower()}

await hass.services.async_call(DOMAIN_LOGGER, SERVICE_SET_LEVEL, log_level_data)
try:
await hass.services.async_call(DOMAIN_LOGGER, SERVICE_SET_LEVEL, log_level_data)

except Exception as ex:
exc_type, exc_obj, tb = sys.exc_info()
line_number = tb.tb_lineno

_LOGGER.error(f"Failed to set log level. Ensure you have logging enabled in configuration.yaml., error: {ex}, line: {line_number}")
6 changes: 6 additions & 0 deletions custom_components/blueiris/helpers/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,14 @@
BI_CAMERA_ATTR_ERROR = "Error"
BI_CAMERA_ATTR_GROUP_CAMERAS = "Group Cameras"

BI_CAMERA_TYPE_SCREEN_CAPTURE = 0
BI_CAMERA_TYPE_USB_FIREWIRE_ANALOG = 2
BI_CAMERA_TYPE_NETWORK_IP = 4
BI_CAMERA_TYPE_BROADCAST = 5
BI_CAMERA_TYPE_SCREEN_CAPTURE_LABEL = "Screen Capture Camera"
BI_CAMERA_TYPE_USB_FIREWIRE_ANALOG_LABEL = "USB, Firewire, or Analog Camera"
BI_CAMERA_TYPE_NETWORK_IP_LABEL = "Network IP Camera"
BI_CAMERA_TYPE_BROADCAST_LABEL = "Broadcast Camera"

ATTR_BLUE_IRIS_CAMERA = {
"optionDisplay": CONF_NAME,
Expand Down
10 changes: 7 additions & 3 deletions custom_components/blueiris/managers/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ def get_camera_device_name(self, camera: CameraData):
def get_camera_device_model(self, camera: CameraData):
if(camera.type is not None):
if(camera.type == BI_CAMERA_TYPE_NETWORK_IP):
camera_type = "Network IP Camera"
camera_type = BI_CAMERA_TYPE_NETWORK_IP_LABEL
elif(camera.type == BI_CAMERA_TYPE_BROADCAST):
camera_type = "Broadcast Camera"
camera_type = BI_CAMERA_TYPE_BROADCAST_LABEL
elif(camera.type == BI_CAMERA_TYPE_SCREEN_CAPTURE):
camera_type = BI_CAMERA_TYPE_SCREEN_CAPTURE_LABEL
elif(camera.type == BI_CAMERA_TYPE_USB_FIREWIRE_ANALOG):
camera_type = BI_CAMERA_TYPE_USB_FIREWIRE_ANALOG_LABEL
else:
camera_type = "Camera " + camera.type
camera_type = "Camera-" + str(camera.type)
else:
if(camera.is_group):
camera_type = "Camera Group"
Expand Down
43 changes: 20 additions & 23 deletions custom_components/blueiris/managers/entity_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def device_manager(self) -> DeviceManager:
def integration_title(self) -> str:
return self.config_manager.config_entry.title

@property
def system_device_name(self) -> str:
return self.device_manager.get_system_device_name()

def set_domain_component(self, domain, async_add_entities, component):
self.domain_component_manager[domain] = {
"async_add_entities": async_add_entities,
Expand Down Expand Up @@ -150,18 +154,19 @@ def create_components(self):
is_admin = self.api.data.get("admin", False)
allowed_profile = config_data.allowed_profile
allowed_schedule = config_data.allowed_schedule
system_device_name = self.system_device_name

if is_admin and (allowed_profile is None or len(allowed_profile) > 0) and (allowed_schedule is None or len(allowed_schedule) > 0) :
for profile_name in available_profiles:
profile_id = available_profiles.index(profile_name)

if allowed_profile is None or str(profile_id) in allowed_profile:
self.generate_profile_switch(profile_id, profile_name)
self.generate_profile_switch(profile_id, profile_name, system_device_name)
for schedule_name in available_schedules:
schedule_id = available_schedules.index(schedule_name)

if allowed_schedule is None or str(schedule_id) in allowed_schedule:
self.generate_schedule_switch(schedule_name)
self.generate_schedule_switch(schedule_name, system_device_name)

mqtt_binary_sensors = []
for camera in available_camera:
Expand Down Expand Up @@ -266,14 +271,12 @@ async def _async_update(self):
except Exception as ex:
self.log_exception(ex, f"Failed to update, step: {step}")

def get_profile_switch(self, profile_id, profile_name) -> EntityData:
def get_profile_switch(self, profile_id, profile_name, system_device_name) -> EntityData:
entity = None

try:
current_profile = self.api.status.get("profile", 0)

device_name = self.device_manager.get_system_device_name()

entity_name = (
f"{self.integration_title} {ATTR_ADMIN_PROFILE} {profile_name}"
)
Expand All @@ -291,17 +294,17 @@ def get_profile_switch(self, profile_id, profile_name) -> EntityData:
entity.state = state
entity.attributes = attributes
entity.icon = DEFAULT_ICON
entity.device_name = device_name
entity.device_name = system_device_name
except Exception as ex:
self.log_exception(
ex, f"Failed to get profile switch {profile_name} (#{profile_id})"
)

return entity

def generate_profile_switch(self, profile_id, profile_name):
def generate_profile_switch(self, profile_id, profile_name, system_device_name):
try:
entity = self.get_profile_switch(profile_id, profile_name)
entity = self.get_profile_switch(profile_id, profile_name, system_device_name)
entity_name = entity.name

self.set_entity(DOMAIN_SWITCH, entity_name, entity)
Expand All @@ -310,14 +313,12 @@ def generate_profile_switch(self, profile_id, profile_name):
ex, f"Failed to generate profile switch {profile_name} (#{profile_id})"
)

def get_schedule_switch(self, schedule_name) -> EntityData:
def get_schedule_switch(self, schedule_name, system_device_name) -> EntityData:
entity = None

try:
current_schedule = self.api.status.get("schedule", 0)

device_name = self.device_manager.get_system_device_name()

entity_name = (
f"{self.integration_title} {ATTR_ADMIN_SCHEDULE} {schedule_name}"
)
Expand All @@ -335,17 +336,17 @@ def get_schedule_switch(self, schedule_name) -> EntityData:
entity.state = state
entity.attributes = attributes
entity.icon = SCHEDULE_ICON
entity.device_name = device_name
entity.device_name = system_device_name
except Exception as ex:
self.log_exception(
ex, f"Failed to get schedule switch {schedule_name}"
)

return entity

def generate_schedule_switch(self, schedule_name):
def generate_schedule_switch(self, schedule_name, system_device_name):
try:
entity = self.get_schedule_switch(schedule_name)
entity = self.get_schedule_switch(schedule_name, system_device_name)
entity_name = entity.name

self.set_entity(DOMAIN_SWITCH, entity_name, entity)
Expand All @@ -360,8 +361,6 @@ def get_main_binary_sensor(self) -> EntityData:
try:
entity_name = f"{self.integration_title} Alerts"

device_name = self.device_manager.get_system_device_name()

unique_id = f"{DOMAIN}-{DOMAIN_BINARY_SENSOR}-MAIN-{entity_name}"

binary_sensors = self.get_entities(DOMAIN_BINARY_SENSOR)
Expand Down Expand Up @@ -399,7 +398,7 @@ def get_main_binary_sensor(self) -> EntityData:
entity.state = state
entity.attributes = attributes
entity.icon = DEFAULT_ICON
entity.device_name = device_name
entity.device_name = self.system_device_name
entity.type = SENSOR_MAIN_NAME
entity.binary_sensor_device_class = BinarySensorDeviceClass.PROBLEM
except Exception as ex:
Expand All @@ -416,12 +415,10 @@ def generate_main_binary_sensor(self):
except Exception as ex:
self.log_exception(ex, "Failed to generate main binary sensor")

def get_camera_entity(self, camera: CameraData, sensor_type_name) -> EntityData:
def get_camera_entity(self, camera: CameraData, sensor_type_name, camera_device_name) -> EntityData:
entity = None

try:
device_name = self.device_manager.get_camera_device_name(camera)

entity_name = f"{self.integration_title} {camera.name} {sensor_type_name}"
unique_id = f"{DOMAIN}-{DOMAIN_BINARY_SENSOR}-{entity_name}"

Expand All @@ -443,7 +440,7 @@ def get_camera_entity(self, camera: CameraData, sensor_type_name) -> EntityData:
entity.state = state
entity.attributes = attributes
entity.icon = DEFAULT_ICON
entity.device_name = device_name
entity.device_name = camera_device_name
entity.topic = state_topic
entity.event = sensor_type_name
entity.binary_sensor_device_class = device_class
Expand All @@ -459,10 +456,10 @@ def generate_camera_binary_sensors(self, camera: CameraData):
entities = []

try:
camera_device_name = self.device_manager.get_camera_device_name(camera)
for sensor_type_name in CAMERA_SENSORS.keys():
if self.config_manager.is_allowed_sensor(camera, sensor_type_name):
entity = self.get_camera_entity(camera, sensor_type_name)

entity = self.get_camera_entity(camera, sensor_type_name, camera_device_name)
entities.append(entity)

for entity in entities:
Expand Down
1 change: 0 additions & 1 deletion custom_components/blueiris/managers/home_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ async def async_update(self, event_time):
except Exception as ex:
exc_type, exc_obj, tb = sys.exc_info()
line_number = tb.tb_lineno

_LOGGER.error(f"Failed to async_update, Error: {ex}, Line: {line_number}")

self._is_updating = False
Expand Down
2 changes: 1 addition & 1 deletion custom_components/blueiris/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"codeowners": ["@elad-bar"],
"requirements": [],
"config_flow": true,
"version": "1.0.11",
"version": "1.0.12",
"iot_class": "local_polling"
}

0 comments on commit 8757b30

Please sign in to comment.