From 5d98552f8e89d2825b32e51da3235304cc6971c3 Mon Sep 17 00:00:00 2001 From: Marc-Olivier Arsenault Date: Fri, 2 Aug 2024 11:23:23 +0000 Subject: [PATCH 1/4] update 3rd party deps --- docs/requirements.txt | 4 ++-- requirements.txt | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 7ba5892..f8f9f2f 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,3 +1,3 @@ -sphinx==7.4.4 -furo==2024.5.6 +sphinx==7.4.7 +furo==2024.7.18 sphinx-toolbox==3.7.0 diff --git a/requirements.txt b/requirements.txt index e032183..86fbfeb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,10 @@ pytest-homeassistant-custom-component==0.13.127 moonraker-api==2.0.5 aiohttp_cors==0.7.0 -Pillow==10.3.0 pre-commit==3.7.1 -sphinx==7.4.4 +sphinx==7.4.7 colorlog==6.8.2 -furo==2024.5.6 -ruff==0.5.2 +furo==2024.7.18 +ruff==0.5.5 ha-ffmpeg==3.2.0 sphinx-toolbox==3.7.0 From c31852d47e7bbda2e134fb43a680fa9b9217491d Mon Sep 17 00:00:00 2001 From: Marc-Olivier Arsenault Date: Fri, 2 Aug 2024 12:02:17 +0000 Subject: [PATCH 2/4] update ha --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 86fbfeb..61db4dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -pytest-homeassistant-custom-component==0.13.127 +pytest-homeassistant-custom-component==0.13.148 moonraker-api==2.0.5 aiohttp_cors==0.7.0 pre-commit==3.7.1 From a6aa8da040794408e4016ddeca58a6d53110cce7 Mon Sep 17 00:00:00 2001 From: Marc-Olivier Arsenault Date: Sat, 10 Aug 2024 12:03:14 +0000 Subject: [PATCH 3/4] Revert "Add some system stats sensors. System Load, MCU Load, Memory Used (#354)" This reverts commit d17985ed3b182d6cd4b0523635e1549695c19fd0. --- custom_components/moonraker/const.py | 1 - custom_components/moonraker/sensor.py | 105 +++----------------------- tests/conftest.py | 34 --------- tests/test_sensor.py | 29 ------- 4 files changed, 10 insertions(+), 159 deletions(-) diff --git a/custom_components/moonraker/const.py b/custom_components/moonraker/const.py index c9bfe4c..95f1da3 100644 --- a/custom_components/moonraker/const.py +++ b/custom_components/moonraker/const.py @@ -47,7 +47,6 @@ class METHODS(Enum): MACHINE_DEVICE_POWER_POST_DEVICE = "machine.device_power.post_device" MACHINE_UPDATE_REFRESH = "machine.update.refresh" MACHINE_UPDATE_STATUS = "machine.update.status" - MACHINE_SYSTEM_INFO = "machine.system_info" PRINTER_EMERGENCY_STOP = "printer.emergency_stop" PRINTER_INFO = "printer.info" PRINTER_GCODE_HELP = "printer.gcode.help" diff --git a/custom_components/moonraker/sensor.py b/custom_components/moonraker/sensor.py index 491f123..589a9a7 100755 --- a/custom_components/moonraker/sensor.py +++ b/custom_components/moonraker/sensor.py @@ -270,25 +270,6 @@ class MoonrakerSensorDescription(SensorEntityDescription): device_class=SensorDeviceClass.DISTANCE, unit=UnitOfLength.MILLIMETERS, ), - MoonrakerSensorDescription( - key="sysload", - name="System Load", - value_fn=lambda sensor: round( - sensor.coordinator.data["status"]["system_stats"]["sysload"], 2 - ), - subscriptions=[("system_stats", "sysload")], - icon="mdi:cpu-64-bit", - state_class=SensorStateClass.MEASUREMENT, - ), - MoonrakerSensorDescription( - key="memused", - name="Memory Used", - value_fn=lambda sensor: calculate_memory_used(sensor.coordinator.data) or 0.0, - subscriptions=[("system_stats", "memavail")], - icon="mdi:memory", - state_class=SensorStateClass.MEASUREMENT, - unit=PERCENTAGE, - ), ] @@ -303,17 +284,8 @@ async def async_setup_entry(hass, entry, async_add_entities): await async_setup_queue_sensors(coordinator, entry, async_add_entities) -async def _machine_system_info_updater(coordinator): - return { - "system_info": ( - await coordinator.async_fetch_data(METHODS.MACHINE_SYSTEM_INFO) - )["system_info"] - } - - async def async_setup_basic_sensor(coordinator, entry, async_add_entities): """Set basic sensor platform.""" - coordinator.add_data_updater(_machine_system_info_updater) coordinator.load_sensor_data(SENSORS) async_add_entities([MoonrakerSensor(coordinator, entry, desc) for desc in SENSORS]) @@ -403,49 +375,7 @@ async def async_setup_optional_sensors(coordinator, entry, async_add_entities): state_class=SensorStateClass.MEASUREMENT, ) sensors.append(desc) - elif split_obj[0] == "mcu": - if len(split_obj) > 1: - key = f"{split_obj[0]}_{split_obj[1]}" - name = obj.replace("_", " ").title() - else: - key = split_obj[0] - name = split_obj[0].title() - desc = MoonrakerSensorDescription( - key=f"{key}_load", - status_key=obj, - name=f"{name} Load", - value_fn=lambda sensor: ( - sensor.coordinator.data["status"][sensor.status_key]["last_stats"][ - "mcu_task_avg" - ] - + 3 - * sensor.coordinator.data["status"][sensor.status_key][ - "last_stats" - ]["mcu_task_stddev"] - ) - / 0.0025 - * 100, - subscriptions=[(obj, "last_stats")], - icon="mdi:cpu-64-bit", - state_class=SensorStateClass.MEASUREMENT, - unit=PERCENTAGE, - ) - sensors.append(desc) - desc = MoonrakerSensorDescription( - key=f"{key}_awake", - status_key=obj, - name=f"{name} Awake", - value_fn=lambda sensor: sensor.coordinator.data["status"][ - sensor.status_key - ]["last_stats"]["mcu_awake"] - / 5 - * 100, - icon="mdi:cpu-64-bit", - subscriptions=[(obj, "last_stats")], - state_class=SensorStateClass.MEASUREMENT, - unit=PERCENTAGE, - ) - sensors.append(desc) + elif split_obj[0] in fan_keys: desc = MoonrakerSensorDescription( key=f"{split_obj[0]}_{split_obj[1]}", @@ -497,8 +427,7 @@ async def async_setup_optional_sensors(coordinator, entry, async_add_entities): ( sensor.coordinator.data["status"][sensor.status_key]["power"] or 0.0 - ) - * 100 + ) * 100 ), subscriptions=[(obj, "power")], icon="mdi:flash", @@ -580,8 +509,7 @@ async def async_setup_optional_sensors(coordinator, entry, async_add_entities): ( sensor.coordinator.data["status"][sensor.status_key]["power"] or 0.0 - ) - * 100 + ) * 100 ), subscriptions=[(obj, "power")], icon="mdi:flash", @@ -658,13 +586,11 @@ async def async_setup_history_sensors(coordinator, entry, async_add_entities): await coordinator.async_refresh() async_add_entities([MoonrakerSensor(coordinator, entry, desc) for desc in sensors]) - async def _queue_updater(coordinator): return { "queue": await coordinator.async_fetch_data(METHODS.SERVER_JOB_QUEUE_STATUS) } - async def async_setup_queue_sensors(coordinator, entry, async_add_entities): """Job queue sensors.""" queue = await coordinator.async_fetch_data(METHODS.SERVER_JOB_QUEUE_STATUS) @@ -677,27 +603,28 @@ async def async_setup_queue_sensors(coordinator, entry, async_add_entities): MoonrakerSensorDescription( key="queue_state", name="Queue State", - value_fn=lambda sensor: sensor.coordinator.data["queue"]["queue_state"], + value_fn=lambda sensor: sensor.coordinator.data["queue"][ + "queue_state" + ], subscriptions=[("queue_state")], ), MoonrakerSensorDescription( key="queue_count", name="Jobs in queue", - value_fn=lambda sensor: len( - sensor.coordinator.data["queue"]["queued_jobs"] - ), + value_fn=lambda sensor: len(sensor.coordinator.data["queue"][ + "queued_jobs" + ]), subscriptions=[("queued_jobs")], icon="mdi:numeric", unit="Jobs", state_class=SensorStateClass.MEASUREMENT, - ), + ) ] coordinator.load_sensor_data(sensors) await coordinator.async_refresh() async_add_entities([MoonrakerSensor(coordinator, entry, desc) for desc in sensors]) - async def _machine_update_updater(coordinator): return { "machine_update": await coordinator.async_fetch_data( @@ -873,15 +800,3 @@ def convert_time(time_s): return ( f"{round(time_s // 3600)}h {round(time_s % 3600 // 60)}m {round(time_s % 60)}s" ) - - -def calculate_memory_used(data): - """Calculate memory used.""" - - if "system_info" not in data: - return None - - total_memory = data["system_info"]["cpu_info"]["total_memory"] - memory_used = total_memory - data["status"]["system_stats"]["memavail"] - percent_mem_used = memory_used / total_memory * 100 - return round(percent_mem_used, 2) diff --git a/tests/conftest.py b/tests/conftest.py index 598d19c..a957b1f 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -46,11 +46,6 @@ def get_data_fixture(): return { "eventtime": 128684.342831779, "status": { - "system_stats": { - "sysload": 0.244140625, - "cputime": 384.86964173, - "memavail": 1291812, - }, "configfile": { "settings": { "output_pin digital": { @@ -174,13 +169,6 @@ def get_data_fixture(): "gcode_move": { "speed_factor": 2.0, }, - "mcu": { - "last_stats": { - "mcu_awake": 0.031, - "mcu_task_avg": 0.000002, - "mcu_task_stddev": 0.000012, - }, - }, }, "printer.info": { "result": { @@ -388,26 +376,6 @@ def get_machine_update_status_fixture(): } -@pytest.fixture(name="get_machine_system_info") -def get_machine_system_info_fixture(): - """Get Machine Update Status fixture.""" - return { - "system_info": { - "cpu_info": { - "cpu_count": 4, - "bits": "64bit", - "processor": "aarch64", - "cpu_desc": "", - "serial_number": "10000000e2e0a55f", - "hardware_desc": "", - "model": "Raspberry Pi Compute Module 4 Rev 1.1", - "total_memory": 1891256, - "memory_units": "kB", - }, - } - } - - @pytest.fixture(name="get_default_api_response") def get_default_api_response_fixure( get_data, @@ -418,7 +386,6 @@ def get_default_api_response_fixure( get_gcode_help, get_power_devices, get_machine_update_status, - get_machine_system_info, ): """Get all the default fixture returned by moonraker.""" return { @@ -430,7 +397,6 @@ def get_default_api_response_fixure( **get_gcode_help, **get_power_devices, **get_machine_update_status, - **get_machine_system_info, } diff --git a/tests/test_sensor.py b/tests/test_sensor.py index b7cb79e..3609af4 100755 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -362,35 +362,6 @@ async def test_no_fan_sensor(hass, get_data, get_printer_objects_list): assert state is None -async def test_multi_mcu_sensor_data(hass, get_data, get_printer_objects_list): - """Test.""" - get_printer_objects_list["objects"].append("mcu Extruder") - get_data["status"]["mcu Extruder"] = { - "last_stats": { - "mcu_awake": 0.031, - "mcu_task_avg": 0.000002, - "mcu_task_stddev": 0.000012, - }, - } - - 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() - - registry = get_entity_registry(hass) - - assert ( - registry.async_get_entity_id("sensor", DOMAIN, "test_mcu_Extruder_load") - is not None - ) - - assert ( - registry.async_get_entity_id("sensor", DOMAIN, "test_mcu_Extruder_awake") - is not None - ) - - async def test_rounding_fan(hass, get_data): """Test.""" get_data["status"]["fan"]["speed"] = 0.33333333333 From 977e38cbb1705071f2af81a8437f41e5d97c26fb Mon Sep 17 00:00:00 2001 From: Marc-Olivier Arsenault Date: Sat, 10 Aug 2024 12:39:11 +0000 Subject: [PATCH 4/4] keep old ha --- requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 61db4dd..641fe97 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ -pytest-homeassistant-custom-component==0.13.148 +pytest-homeassistant-custom-component==0.13.128 moonraker-api==2.0.5 aiohttp_cors==0.7.0 -pre-commit==3.7.1 +pre-commit==3.8.0 sphinx==7.4.7 colorlog==6.8.2 furo==2024.7.18 -ruff==0.5.5 +ruff==0.5.6 ha-ffmpeg==3.2.0 sphinx-toolbox==3.7.0