Skip to content

Commit

Permalink
Merge pull request #64 from mikey0000/adding-further-configuration
Browse files Browse the repository at this point in the history
fix conversion to us customary
  • Loading branch information
mikey0000 authored Aug 13, 2024
2 parents 4a245eb + 59965ab commit 32cabf6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
19 changes: 16 additions & 3 deletions custom_components/mammotion/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from pymammotion.data.model.device import MowingDevice
from pymammotion.mammotion.devices import MammotionBaseBLEDevice
from pymammotion.proto.luba_msg import LubaMsg
from pymammotion.proto.mctrl_sys import RptInfoType, RptAct
from pymammotion.utility.constant import WorkMode

from .const import COMMAND_EXCEPTIONS, DOMAIN, LOGGER

Expand Down Expand Up @@ -76,9 +78,17 @@ async def async_start_stop_blades(self, start_stop: bool) -> None:
async def async_blade_height(self, height: int) -> None:
await self.async_send_command("set_blade_height", height=height)

async def async_send_command(self, command: str, kwargs) -> None:
try:

async def async_request_iot_sync(self) -> None:
await self.async_send_command("request_iot_sys", rpt_act=RptAct.RPT_START,
rpt_info_type=[RptInfoType.RIT_CONNECT, RptInfoType.RIT_DEV_STA],
timeout=1000,
period=3000,
no_change_period=4000,
count=0)

async def async_send_command(self, command: str, **kwargs) -> None:
try:
await self.device.command(command, **kwargs)
except COMMAND_EXCEPTIONS as exc:
raise HomeAssistantError(
Expand All @@ -97,11 +107,14 @@ async def _async_update_data(self) -> MowingDevice:

self.device.update_device(ble_device)
try:
await self.device.command("get_report_cfg")
await self.async_request_iot_sync()
if self.device.luba_msg.device.sys.toapp_report_data.dev.sys_status != WorkMode.MODE_WORKING:
await self.async_send_command("get_report_cfg")
except COMMAND_EXCEPTIONS as exc:
self.update_failures += 1
raise UpdateFailed(f"Updating Mammotion device failed: {exc}") from exc


LOGGER.debug("Updated Mammotion device %s", self.device_name)
LOGGER.debug("================= Debug Log =================")
LOGGER.debug("Mammotion device data: %s", asdict(self.device.luba_msg))
Expand Down
8 changes: 3 additions & 5 deletions custom_components/mammotion/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from homeassistant.util.unit_conversion import DistanceConverter, SpeedConverter
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM, LENGTH_UNITS
from pymammotion.data.model.enums import RTKStatus
from pymammotion.proto.luba_msg import ReportInfoData
from pymammotion.utility.constant.device_constant import device_mode, PosType
Expand All @@ -25,8 +25,6 @@
from .coordinator import MammotionDataUpdateCoordinator
from .entity import MammotionBaseEntity


LENGTH_UNITS = DistanceConverter.VALID_UNITS
SPEED_UNITS = SpeedConverter.VALID_UNITS

@dataclass(frozen=True, kw_only=True)
Expand Down Expand Up @@ -214,8 +212,8 @@ def native_value(self) -> StateType:

if unit_system is US_CUSTOMARY_SYSTEM:
if unit in LENGTH_UNITS:
return DistanceConverter.convert(current_value, LENGTH_UNITS[unit], UnitOfLength.FEET)
return DistanceConverter.convert(current_value, UnitOfLength[unit], UnitOfLength.FEET)
if unit in SPEED_UNITS:
return SpeedConverter.convert(current_value, SPEED_UNITS[unit], UnitOfSpeed.FEET_PER_SECOND)
return SpeedConverter.convert(current_value, UnitOfSpeed[unit], UnitOfSpeed.FEET_PER_SECOND)

return current_value

0 comments on commit 32cabf6

Please sign in to comment.