Skip to content

Commit

Permalink
add camera brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
mikey0000 committed Nov 8, 2024
1 parent 2a0d565 commit 3d97855
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/mammotion/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
],
"iot_class": "local_push",
"requirements": [
"pymammotion==0.3.1"
"pymammotion==0.3.2"
]
}
22 changes: 20 additions & 2 deletions custom_components/mammotion/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
)
Expand All @@ -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)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 3d97855

Please sign in to comment.