Skip to content
This repository was archived by the owner on Mar 8, 2022. It is now read-only.

Commit 556f985

Browse files
committed
fix circular import and rearrange events as statusEvents must be the first one
1 parent e5a77e3 commit 556f985

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

deebotozmo/events.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import List, TypeVar, Generic, Callable, Awaitable, Optional
77

88
from deebotozmo.models import Room, VacuumState
9-
from deebotozmo.vacuum_bot import VacuumBot
109

1110
_LOGGER = logging.getLogger(__name__)
1211

@@ -134,7 +133,7 @@ def request_refresh(self):
134133

135134
class PollingEventEmitter(EventEmitter[T]):
136135

137-
def __init__(self, refresh_interval: int, refresh_function: Callable[[], Awaitable[None]], vacuum_bot: VacuumBot):
136+
def __init__(self, refresh_interval: int, refresh_function: Callable[[], Awaitable[None]], vacuum_bot: "VacuumBot"):
138137
super().__init__(refresh_function)
139138
self._refresh_task: Optional[Task] = None
140139
self._refresh_interval: int = refresh_interval

deebotozmo/util.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from deebotozmo.commands import Command
77
from deebotozmo.events import PollingEventEmitter, EventEmitter
8-
from deebotozmo.vacuum_bot import VacuumBot
98

109

1110
def str_to_bool_or_cert(s: Union[bool, str]) -> Union[bool, str]:
@@ -54,7 +53,7 @@ def get_EventEmitter(event_type: Type[T], commands: [Command],
5453

5554

5655
def get_PollingEventEmitter(event_type: Type[T], refresh_interval: int, commands: [Command],
57-
execute_command: Callable[[Command], Awaitable[None]], vacuum_bot: VacuumBot) -> \
56+
execute_command: Callable[[Command], Awaitable[None]], vacuum_bot: "VacuumBot") -> \
5857
PollingEventEmitter[T]:
5958
return PollingEventEmitter[event_type](refresh_interval, get_refresh_function(commands, execute_command),
6059
vacuum_bot)

deebotozmo/vacuum_bot.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
from typing import Union
1+
import asyncio
2+
import logging
3+
from typing import Union, Optional, List
24

35
import aiohttp
46

57
from deebotozmo.commands import *
68
from deebotozmo.constants import ERROR_CODES, FAN_SPEED_FROM_ECOVACS, COMPONENT_FROM_ECOVACS, WATER_LEVEL_FROM_ECOVACS
79
from deebotozmo.ecovacs_api import EcovacsAPI
810
from deebotozmo.ecovacs_json import EcovacsJSON
9-
from deebotozmo.events import *
11+
from deebotozmo.events import EventEmitter, ErrorEvent, PollingEventEmitter, LifeSpanEvent, FanSpeedEvent, \
12+
CleanLogEvent, WaterInfoEvent, BatteryEvent, StatusEvent, StatsEvent, CleanLogEntry
1013
from deebotozmo.map import Map
1114
from deebotozmo.models import *
1215
from deebotozmo.util import get_PollingEventEmitter, get_EventEmitter
@@ -46,10 +49,10 @@ def __init__(
4649

4750
self._map = Map(self.execute_command)
4851

49-
self.errorEvents: EventEmitter[ErrorEvent] = get_EventEmitter(ErrorEvent, [GetError()], self.execute_command)
52+
self.statusEvents: EventEmitter[StatusEvent] = \
53+
get_EventEmitter(StatusEvent, [GetChargeState(), GetCleanInfo(self.vacuum)], self.execute_command)
5054

51-
self.lifespanEvents: PollingEventEmitter[LifeSpanEvent] = \
52-
get_PollingEventEmitter(LifeSpanEvent, 60, [GetLifeSpan()], self.execute_command, self)
55+
self.errorEvents: EventEmitter[ErrorEvent] = get_EventEmitter(ErrorEvent, [GetError()], self.execute_command)
5356

5457
self.fanSpeedEvents: EventEmitter[FanSpeedEvent] = \
5558
get_EventEmitter(FanSpeedEvent, [GetFanSpeed()], self.execute_command)
@@ -63,12 +66,12 @@ def __init__(
6366
self.batteryEvents: EventEmitter[BatteryEvent] = \
6467
get_EventEmitter(BatteryEvent, [GetBattery()], self.execute_command)
6568

66-
self.statusEvents: EventEmitter[StatusEvent] = \
67-
get_EventEmitter(StatusEvent, [GetChargeState(), GetCleanInfo(self.vacuum)], self.execute_command)
68-
6969
self.statsEvents: EventEmitter[StatsEvent] = \
7070
get_EventEmitter(StatsEvent, [GetStats()], self.execute_command)
7171

72+
self.lifespanEvents: PollingEventEmitter[LifeSpanEvent] = \
73+
get_PollingEventEmitter(LifeSpanEvent, 60, [GetLifeSpan()], self.execute_command, self)
74+
7275
@property
7376
def map(self) -> Map:
7477
return self._map

0 commit comments

Comments
 (0)