Skip to content

Commit

Permalink
ruffed files.
Browse files Browse the repository at this point in the history
  • Loading branch information
sca075 committed Dec 7, 2024
1 parent 606ae7f commit b8b0fea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
30 changes: 14 additions & 16 deletions custom_components/mqtt_vacuum_camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@


async def async_setup_entry(
hass: core.HomeAssistant,
config_entry: config_entries.ConfigEntry,
async_add_entities,
hass: core.HomeAssistant,
config_entry: config_entries.ConfigEntry,
async_add_entities,
) -> None:
"""Setup camera from a config entry created in the integrations UI."""
config = hass.data[DOMAIN][config_entry.entry_id]
Expand Down Expand Up @@ -145,7 +145,7 @@ def _init_clear_www_folder(self):
"""Remove PNG and ZIP's stored in HA config WWW"""
# If enable_snapshots check if for png in www
if not self._shared.enable_snapshots and os.path.isfile(
f"{self._homeassistant_path}/www/snapshot_{self._file_name}.png"
f"{self._homeassistant_path}/www/snapshot_{self._file_name}.png"
):
os.remove(f"{self._homeassistant_path}/www/snapshot_{self._file_name}.png")
# If there is a log zip in www remove it
Expand Down Expand Up @@ -203,13 +203,13 @@ def is_streaming(self) -> bool:
"""Return true if the device is streaming."""
updated_status = self._shared.vacuum_state
self._attr_is_streaming = (
updated_status not in NOT_STREAMING_STATES
or not self._shared.vacuum_bat_charged
updated_status not in NOT_STREAMING_STATES
or not self._shared.vacuum_bat_charged
)
return self._attr_is_streaming

def camera_image(
self, width: Optional[int] = None, height: Optional[int] = None
self, width: Optional[int] = None, height: Optional[int] = None
) -> Optional[bytes]:
"""Camera Image"""
return self.Image
Expand Down Expand Up @@ -252,8 +252,8 @@ async def handle_obstacle_view(self, event):
return await self.async_update()

if (
self._shared.obstacles_data
and self._shared.camera_mode == CameraModes.MAP_VIEW
self._shared.obstacles_data
and self._shared.camera_mode == CameraModes.MAP_VIEW
):
_LOGGER.debug(f"Received event: {event.event_type}, Data: {event.data}")
if event.data.get("entity_id") == self.entity_id:
Expand Down Expand Up @@ -405,8 +405,6 @@ async def download_image(url: str, storage_path: str, filename: str):
_LOGGER.error(f"Error downloading image: {e}")
return None



@property
def should_poll(self) -> bool:
"""ON/OFF Camera Polling"""
Expand Down Expand Up @@ -624,12 +622,12 @@ def _log_memory_usage(self, proc):
"""Log the memory usage."""
memory_percent = round(
(
(proc.memory_info()[0] / 2.0**30)
/ (ProcInsp().psutil.virtual_memory().total / 2.0**30)
(proc.memory_info()[0] / 2.0**30)
/ (ProcInsp().psutil.virtual_memory().total / 2.0**30)
)
* 100,
2,
)
)
_LOGGER.debug(
f"{self._file_name} Camera Memory usage in GB: "
f"{round(proc.memory_info()[0] / 2. ** 30, 2)}, {memory_percent}% of Total."
Expand Down Expand Up @@ -682,8 +680,8 @@ async def run_async_pil_to_bytes(self, pil_img):
pil_img_list = [pil_img for _ in range(num_processes)]
loop = get_event_loop()

with (ThreadPoolExecutor(
max_workers=1, thread_name_prefix=f"{self._file_name}_camera")
with ThreadPoolExecutor(
max_workers=1, thread_name_prefix=f"{self._file_name}_camera"
) as executor:
tasks = [
loop.run_in_executor(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/mqtt_vacuum_camera/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async def async_update_sensor_data(self, sensor_data):

if not vacuum_room:
vacuum_room = {"in_room": "Unsupported"}
if last_loaded_map=={}:
if last_loaded_map == {}:
last_loaded_map = {"name", "Default"}

formatted_data = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async def async_draw_obstacle(
self.img_h.shared.obstacles_data = compose_obstacle_links(
self.img_h.shared.vacuum_ips, obstacle_objects
)
elif self.img_h.shared.vacuum_api: # Fall back to API usage if no IP.
elif self.img_h.shared.vacuum_api: # Fall back to API usage if no IP.
self.img_h.shared.obstacles_data = compose_obstacle_links(
self.img_h.shared.vacuum_api.split("http://")[1], obstacle_objects
)
Expand Down

0 comments on commit b8b0fea

Please sign in to comment.