-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added room name information to Position object #397
base: dev
Are you sure you want to change the base?
Changes from 3 commits
53b26ce
b28f192
f04d926
72be904
37a76de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,15 @@ | |
StateEvent, | ||
StatsEvent, | ||
TotalStatsEvent, | ||
RoomsEvent, Position | ||
) | ||
from .logging_filter import get_logger | ||
from .map import Map | ||
from .map import Map, Room | ||
from .messages import get_message | ||
from .models import DeviceInfo, State | ||
|
||
from shapely.geometry import Point | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Callable | ||
|
||
|
@@ -53,6 +56,8 @@ def __init__( | |
self._available_task: asyncio.Task[Any] | None = None | ||
self._unsubscribe: Callable[[], None] | None = None | ||
|
||
self.rooms: list[Room] = [] | ||
|
||
self.fw_version: str | None = None | ||
self.mac: str | None = None | ||
self.events: Final[EventBus] = EventBus( | ||
|
@@ -80,6 +85,12 @@ async def on_pos(event: PositionsEvent) -> None: | |
|
||
self.events.subscribe(PositionsEvent, on_pos) | ||
|
||
async def on_rooms(event: RoomsEvent) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should go into |
||
self.rooms = event.rooms | ||
self.events.request_refresh(PositionsEvent) | ||
|
||
self.events.subscribe(RoomsEvent, on_rooms) | ||
|
||
async def on_state(event: StateEvent) -> None: | ||
if event.state == State.DOCKED: | ||
self.events.request_refresh(CleanLogEvent) | ||
|
@@ -155,7 +166,7 @@ async def _execute_command(self, command: Command) -> bool: | |
"""Execute given command.""" | ||
async with self._semaphore: | ||
if await command.execute( | ||
self._authenticator, self.device_info, self.events | ||
self._authenticator, self.device_info, self.events, self.rooms | ||
): | ||
self._set_available(available=True) | ||
return True | ||
|
@@ -184,10 +195,17 @@ def _handle_message( | |
_LOGGER.debug("Try to handle message %s: %s", message_name, message_data) | ||
|
||
if message := get_message(message_name, self.device_info.data_type): | ||
|
||
rooms = self.rooms | ||
|
||
if isinstance(message_data, dict): | ||
data = message_data | ||
if message_name == "onPos": | ||
data["rooms"] = rooms | ||
else: | ||
data = json.loads(message_data) | ||
if message_name == "onPos": | ||
data["body"]["data"]["rooms"] = rooms | ||
|
||
fw_version = data.get("header", {}).get("fwVer", None) | ||
if fw_version: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ class Position: | |
type: PositionType | ||
x: int | ||
y: int | ||
room: str | None | ||
|
||
|
||
@dataclass(frozen=True) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import struct | ||
from typing import Any, Final | ||
import zlib | ||
import shapely.geometry | ||
|
||
from PIL import Image, ImageColor, ImageOps, ImagePalette | ||
import svg | ||
|
@@ -407,7 +408,10 @@ async def on_map_set(event: MapSetEvent) -> None: | |
|
||
async def on_map_subset(event: MapSubsetEvent) -> None: | ||
if event.type == MapSetType.ROOMS and event.name: | ||
room = Room(event.name, event.id, event.coordinates) | ||
decompressed_coords = _decompress_7z_base64_data(event.coordinates).decode('utf-8') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compressed coordinates are Part of |
||
coordinates = [tuple(map(float, pair.split(','))) for pair in decompressed_coords.split(';')] | ||
room = Room(event.name, event.id, decompressed_coords, shapely.geometry.Polygon(coordinates)) | ||
|
||
if self._map_data.rooms.get(event.id, None) != room: | ||
self._map_data.rooms[room.id] = room | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
getPos
specific code should go into theGetPos
class and not in the generalCommand
class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to pass rooms parameter to GetPos class. This is the only way I've found. Help me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code should be in
map.py
and not in the command. The commands module is what we get from the API and we should not do calculations there.Instead I think the calculation should be part of
map.py
, where you already have the rooms and the position