Skip to content

Commit

Permalink
Sending SyncTimeCommand after connect
Browse files Browse the repository at this point in the history
  • Loading branch information
bergdahl committed Jun 27, 2024
1 parent af2e800 commit 2848cf1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,5 @@ You can reach me in [#jonnys-place](https://discord.gg/SeHKWPu9Cw) on Brian Loug

# TODO

- Add a `ReqSyncTime` call to set time after connecting to the device
- Add/Rename the diagnostics sensors to adhere to the last reverse engineering findings
- Add reconnect logic after connection lost event
14 changes: 8 additions & 6 deletions custom_components/growcube/coordinator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
from datetime import datetime
from typing import Optional, List, Tuple

from growcube_client import GrowcubeClient, GrowcubeReport, Channel, WateringMode
Expand All @@ -12,7 +13,7 @@
CheckSensorNotConnectedGrowcubeReport,
CheckSensorLockGrowcubeReport,
LockStateGrowcubeReport)
from growcube_client import WateringModeCommand
from growcube_client import WateringModeCommand, SyncTimeCommand
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.const import STATE_UNAVAILABLE, STATE_OK, STATE_PROBLEM, STATE_LOCKED, STATE_OPEN, STATE_CLOSED
import logging
Expand Down Expand Up @@ -77,6 +78,9 @@ async def connect(self) -> Tuple[bool, str]:
while not self.data.device_id:
await asyncio.sleep(0.1)
_LOGGER.debug("Growcube device id: %s", self.data.device_id)
time_command = SyncTimeCommand(datetime.now())
_LOGGER.debug("Sending SyncTimeCommand")
self.client.send_command(time_command)
return True, ""

@staticmethod
Expand Down Expand Up @@ -152,18 +156,16 @@ def handle_report(self, report: GrowcubeReport):
elif isinstance(report, CheckSensorNotConnectedGrowcubeReport):
_LOGGER.debug(f"{self.data.device_id}: Check sensor, channel {report.channel}")
self.data.sensor_state[report.channel.value] = True
#self.moisture_sensors[report.channel.value].update(None)
# self.moisture_sensors[report.channel.value].update(None)
elif isinstance(report, LockStateGrowcubeReport):
_LOGGER.debug(f"{self.data.device_id}: Lock state, {report.lock_state}")
self.data.device_lock_state = report.lock_state
#self.async_set_updated_data(self.model)

# self.async_set_updated_data(self.model)

async def water_plant(self, channel: int) -> None:
await self.client.water_plant(Channel(channel), 5)


async def handle_water_plant(self, call: ServiceCall):
async def handle_water_plant(self, call: ServiceCall):
# Validate channel
channel_str = call.data.get('channel')
duration_str = call.data.get('duration')
Expand Down

0 comments on commit 2848cf1

Please sign in to comment.