Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check for empty updates #247

Merged
merged 2 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions custom_components/moonraker/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,27 +115,40 @@ async def async_camera_image(
self, width: int | None = None, height: int | None = None
) -> bytes | None:
"""Return current camera image."""
_LOGGER.debug("Trying to get thumbnail ")
if (
self.coordinator.data["status"]["print_stats"]["state"]
!= PRINTSTATES.PRINTING.value
):
_LOGGER.debug("Not printing, no thumbnail")
return None

del width, height

new_path = self.coordinator.data["thumbnails_path"]
_LOGGER.debug(f"Thumbnail new_path: {new_path}")
if self._current_path == new_path and self._current_pic is not None:
_LOGGER.debug("no change in thumbnail, returning cached")
return self._current_pic

if new_path == "" or new_path is None:
self._current_pic = None
self._current_path = ""
_LOGGER.debug("Empty path, no thumbnail")
return None

_LOGGER.debug(
f"Fetching new thumbnail: http://{self.url}/server/files/gcodes/{new_path}"
)
response = await self._session.get(
f"http://{self.url}/server/files/gcodes/{new_path}"
)

self._current_path = new_path
self._current_pic = await response.read()

_LOGGER.debug(
f"Size of thumbnail: {self._current_pic.width} x {self._current_pic.height}"
)

return self._current_pic
6 changes: 4 additions & 2 deletions custom_components/moonraker/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ async def async_setup_machine_update_sensors(coordinator, entry, async_add_entit
machine_status = await coordinator.async_fetch_data(METHODS.MACHINE_UPDATE_STATUS)
if machine_status.get("error"):
return

coordinator.add_data_updater(_machine_update_updater)
sensors = []

Expand All @@ -509,7 +508,10 @@ async def async_setup_machine_update_sensors(coordinator, entry, async_add_entit
entity_registry_enabled_default=False,
)
)
else:
elif (
"version" in machine_status["version_info"][version_info]
and "remote_version" in machine_status["version_info"][version_info]
):
sensors.append(
MoonrakerSensorDescription(
key=f"machine_update_{version_info}",
Expand Down
17 changes: 17 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,20 @@ async def test_update_no_system_update(hass, get_machine_update_status):
entity_registry = er.async_get(hass)
entity = entity_registry.async_get("sensor.mainsail_machine_update_system")
assert entity is None


async def test_update_no_info_item(hass, get_machine_update_status):
"""Test update available."""
get_machine_update_status["version_info"]["mainsail"] = {}

config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test")
config_entry.add_to_hass(hass)
assert await async_setup_entry(hass, config_entry)
await hass.async_block_till_done()

entity_registry = er.async_get(hass)
entity = entity_registry.async_get("sensor.mainsail_version_mainsail")
assert entity is None

entity = entity_registry.async_get("sensor.mainsail_machine_update_system")
assert entity is not None
Loading