use protocol for locations
This commit is contained in:
parent
8d70dd725d
commit
52b6acbcbf
2 changed files with 19 additions and 8 deletions
|
@ -3,18 +3,29 @@ from typing import Union, Tuple, Optional
|
|||
from dataclasses import dataclass
|
||||
|
||||
from my.core import __NOT_HPI_MODULE__
|
||||
from my.core.compat import Protocol
|
||||
|
||||
DateIsh = Union[datetime, date, str]
|
||||
|
||||
LatLon = Tuple[float, float]
|
||||
|
||||
|
||||
# TODO: add timezone to this? can use timezonefinder in tz provider instead though
|
||||
|
||||
# converted from namedtuple to a dataclass so datasource field can be added optionally
|
||||
# if we want, can eventually be converted back to a namedtuple when all datasources are compliant
|
||||
@dataclass
|
||||
class Location:
|
||||
class LocationProtocol(Protocol):
|
||||
lat: float
|
||||
lon: float
|
||||
dt: datetime
|
||||
accuracy: Optional[float]
|
||||
elevation: Optional[float]
|
||||
datasource: Optional[str] = None # which module provided this, useful for debugging
|
||||
|
||||
|
||||
# TODO: add timezone to this? can use timezonefinder in tz provider instead though
|
||||
|
||||
|
||||
# converted from namedtuple to a dataclass so datasource field can be added optionally
|
||||
# if we want, can eventually be converted back to a namedtuple when all datasources are compliant
|
||||
@dataclass
|
||||
class Location(LocationProtocol):
|
||||
lat: float
|
||||
lon: float
|
||||
dt: datetime
|
||||
|
|
|
@ -3,11 +3,11 @@ from dataclasses import dataclass
|
|||
from typing import Optional
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from ..common import Location
|
||||
from ..common import LocationProtocol, Location
|
||||
|
||||
|
||||
@dataclass
|
||||
class FallbackLocation:
|
||||
class FallbackLocation(LocationProtocol):
|
||||
lat: float
|
||||
lon: float
|
||||
dt: datetime
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue