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/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..641fe97 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,10 @@ -pytest-homeassistant-custom-component==0.13.127 +pytest-homeassistant-custom-component==0.13.128 moonraker-api==2.0.5 aiohttp_cors==0.7.0 -Pillow==10.3.0 -pre-commit==3.7.1 -sphinx==7.4.4 +pre-commit==3.8.0 +sphinx==7.4.7 colorlog==6.8.2 -furo==2024.5.6 -ruff==0.5.2 +furo==2024.7.18 +ruff==0.5.6 ha-ffmpeg==3.2.0 sphinx-toolbox==3.7.0 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