diff --git a/custom_components/mammotion/manifest.json b/custom_components/mammotion/manifest.json index d6cb499..227e101 100644 --- a/custom_components/mammotion/manifest.json +++ b/custom_components/mammotion/manifest.json @@ -30,6 +30,6 @@ ], "iot_class": "local_push", "requirements": [ - "pymammotion==0.3.1" + "pymammotion==0.3.2" ] } diff --git a/custom_components/mammotion/sensor.py b/custom_components/mammotion/sensor.py index f1d6157..2f303e7 100644 --- a/custom_components/mammotion/sensor.py +++ b/custom_components/mammotion/sensor.py @@ -25,6 +25,7 @@ from pymammotion.data.model.enums import RTKStatus from pymammotion.utility.constant.device_constant import ( PosType, + camera_brightness, device_connection, device_mode, ) @@ -54,6 +55,18 @@ class MammotionSensorEntityDescription(SensorEntityDescription): ), ) +LUBA_2_YUKA_ONLY_TYPES: tuple[MammotionSensorEntityDescription, ...] = ( + MammotionSensorEntityDescription( + key="camera_brightness", + state_class=None, + device_class=None, + native_unit_of_measurement=None, + value_fn=lambda mower_data: camera_brightness( + mower_data.report_data.work.vision_info.brightness + ), + ), +) + SENSOR_TYPES: tuple[MammotionSensorEntityDescription, ...] = ( MammotionSensorEntityDescription( key="battery_percent", @@ -244,6 +257,12 @@ async def async_setup_entry( for description in LUBA_SENSOR_ONLY_TYPES ) + if not DeviceType.is_luba1(coordinator.device_name): + async_add_entities( + MammotionSensorEntity(coordinator, description) + for description in LUBA_2_YUKA_ONLY_TYPES + ) + async_add_entities( MammotionSensorEntity(coordinator, description) for description in SENSOR_TYPES ) @@ -268,5 +287,4 @@ def __init__( @property def native_value(self) -> StateType: """Return the state of the sensor.""" - current_value = self.entity_description.value_fn(self.coordinator.data) - return current_value + return self.entity_description.value_fn(self.coordinator.data) diff --git a/pyproject.toml b/pyproject.toml index 5c797b5..2dd9f4e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ readme = "README.md" [tool.poetry.dependencies] python = "~3.12.0" -pymammotion = "0.3.1" +pymammotion = "0.3.2" homeassistant = "^2024.9.0" autotyping = "^24.3.0"