diff --git a/CHANGELOG.md b/CHANGELOG.md index 974ef9e..73a60f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/custom_components/blueiris/helpers/__init__.py b/custom_components/blueiris/helpers/__init__.py index c371c1c..59c7977 100644 --- a/custom_components/blueiris/helpers/__init__.py +++ b/custom_components/blueiris/helpers/__init__.py @@ -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}") diff --git a/custom_components/blueiris/helpers/const.py b/custom_components/blueiris/helpers/const.py index 4a66ee9..e23d2ba 100644 --- a/custom_components/blueiris/helpers/const.py +++ b/custom_components/blueiris/helpers/const.py @@ -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, diff --git a/custom_components/blueiris/managers/device_manager.py b/custom_components/blueiris/managers/device_manager.py index 9e33a98..b0e7032 100644 --- a/custom_components/blueiris/managers/device_manager.py +++ b/custom_components/blueiris/managers/device_manager.py @@ -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" diff --git a/custom_components/blueiris/managers/entity_manager.py b/custom_components/blueiris/managers/entity_manager.py index 3cf0689..88b0422 100644 --- a/custom_components/blueiris/managers/entity_manager.py +++ b/custom_components/blueiris/managers/entity_manager.py @@ -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, @@ -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: @@ -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}" ) @@ -291,7 +294,7 @@ 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})" @@ -299,9 +302,9 @@ def get_profile_switch(self, profile_id, profile_name) -> EntityData: 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) @@ -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}" ) @@ -335,7 +336,7 @@ 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}" @@ -343,9 +344,9 @@ def get_schedule_switch(self, schedule_name) -> EntityData: 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) @@ -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) @@ -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: @@ -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}" @@ -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 @@ -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: diff --git a/custom_components/blueiris/managers/home_assistant.py b/custom_components/blueiris/managers/home_assistant.py index 69c6750..bcb9427 100644 --- a/custom_components/blueiris/managers/home_assistant.py +++ b/custom_components/blueiris/managers/home_assistant.py @@ -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 diff --git a/custom_components/blueiris/manifest.json b/custom_components/blueiris/manifest.json index 6b4a3b8..6f303f0 100644 --- a/custom_components/blueiris/manifest.json +++ b/custom_components/blueiris/manifest.json @@ -11,6 +11,6 @@ "codeowners": ["@elad-bar"], "requirements": [], "config_flow": true, - "version": "1.0.11", + "version": "1.0.12", "iot_class": "local_polling" }