v.0.10.0 redesign prj structure, multi dev containers
This commit is contained in:
9
pico-client/classes/__init__.py
Normal file
9
pico-client/classes/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from .current_condition import CurrentCondition
|
||||
from .air_quality import AirQuality
|
||||
from .condition import Condition
|
||||
from .location import Location
|
||||
from .response_status import ResponseStatus
|
||||
from .weather_response import WeatherResponse
|
||||
from .weather import Weather
|
||||
|
||||
__all__ = ["Weather", "AirQuality","Condition","CurrentCondition","Location", "ResponseStatus","WeatherResponse"]
|
||||
15
pico-client/classes/air_quality.py
Normal file
15
pico-client/classes/air_quality.py
Normal file
@@ -0,0 +1,15 @@
|
||||
class AirQuality:
|
||||
def __init__(self, **kwargs):
|
||||
# Required pollutants
|
||||
self.co = float(kwargs.get('co', 0))
|
||||
self.no2 = float(kwargs.get('no2', 0))
|
||||
self.o3 = float(kwargs.get('o3', 0))
|
||||
self.so2 = float(kwargs.get('so2', 0))
|
||||
self.pm2_5 = float(kwargs.get('pm2_5'))
|
||||
self.pm10 = float(kwargs.get('pm10', 0))
|
||||
# Air quality indices
|
||||
self.us_epa_index = int(kwargs.get('us-epa-index', 0))
|
||||
self.gb_defra_index = int(kwargs.get('gb-defra-index', 0))
|
||||
|
||||
def __repr__(self):
|
||||
return f'AirQuality(CO={self.co}, NO2={self.no2}, O3={self.o3}, PM2.5={self.pm2_5})'
|
||||
7
pico-client/classes/condition.py
Normal file
7
pico-client/classes/condition.py
Normal file
@@ -0,0 +1,7 @@
|
||||
class Condition:
|
||||
def __init__(self, **kwargs):
|
||||
self.text = kwargs.get('text')
|
||||
self.icon = kwargs.get('icon')
|
||||
|
||||
def __repr__(self):
|
||||
return f'Condition(text={self.text}, icon={self.icon})'
|
||||
24
pico-client/classes/current_condition.py
Normal file
24
pico-client/classes/current_condition.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from .condition import Condition
|
||||
from .air_quality import AirQuality
|
||||
|
||||
class CurrentCondition:
|
||||
def __init__(
|
||||
self,
|
||||
# condition,
|
||||
# air_quality,
|
||||
**kwargs,
|
||||
):
|
||||
self.last_updated = kwargs.get('last_updated', '')
|
||||
self.temp_c = float(kwargs.get('temp_c', 0))
|
||||
self.is_day = int(kwargs.get('is_day', 0))
|
||||
self.condition = Condition(**kwargs.get('condition'))
|
||||
self.wind_kph = float(kwargs.get('wind_kph', 0))
|
||||
self.wind_dir = kwargs.get('wind_dir', '')
|
||||
self.pressure_mb = float(kwargs.get('pressure_mb', 0))
|
||||
self.humidity = int(kwargs.get('humidity', 0))
|
||||
self.cloud = int(kwargs.get('cloud', 0))
|
||||
self.feelslike_c = float(kwargs.get('feelslike_c', 0))
|
||||
self.air_quality = AirQuality(**kwargs.get('air_quality'))
|
||||
|
||||
def __repr__(self):
|
||||
return f'CurrentCondition(condition={self.condition}, air_quality={self.air_quality}, last_updated={self.last_updated}, temp_c={self.temp_c}, wind_dir={self.wind_dir}, wind_kph={self.wind_kph})'
|
||||
9
pico-client/classes/location.py
Normal file
9
pico-client/classes/location.py
Normal file
@@ -0,0 +1,9 @@
|
||||
class Location:
|
||||
def __init__(self, **kwargs):
|
||||
self.name = kwargs.get('name', '')
|
||||
self.region = kwargs.get('region', '')
|
||||
self.country = kwargs.get('country', '')
|
||||
self.localtime = kwargs.get('localtime', '')
|
||||
|
||||
def __repr__(self):
|
||||
return f"Location(name='{self.name}', region='{self.region}', country='{self.country}', localtime='{self.localtime}')"
|
||||
46
pico-client/classes/response_status.py
Normal file
46
pico-client/classes/response_status.py
Normal file
@@ -0,0 +1,46 @@
|
||||
class ResponseStatus:
|
||||
|
||||
def __init__(self, code: int=0, message:str="", error_text:str=""):
|
||||
self._code = code
|
||||
self._message = message
|
||||
self._error_text = error_text
|
||||
|
||||
@property
|
||||
def error_text(self):
|
||||
"""Get the status code"""
|
||||
return self._error_text
|
||||
|
||||
@error_text.setter
|
||||
def error_text(self, value):
|
||||
self._error_text = value
|
||||
|
||||
# Status Code property with validation
|
||||
@property
|
||||
def code(self):
|
||||
"""Get the status code"""
|
||||
return self._code
|
||||
|
||||
@code.setter
|
||||
def code(self, value):
|
||||
"""Set the status code with validation"""
|
||||
if not isinstance(value, int):
|
||||
raise TypeError("code must be an integer")
|
||||
if value < 0 or value > 599:
|
||||
raise ValueError("code must be between 0 and 599")
|
||||
self._code = value
|
||||
|
||||
# Status Message property with validation
|
||||
@property
|
||||
def message(self):
|
||||
"""Get the status message"""
|
||||
return self._message
|
||||
|
||||
@message.setter
|
||||
def message(self, value):
|
||||
"""Set the status message with validation"""
|
||||
if not isinstance(value, str):
|
||||
raise TypeError("message must be a string")
|
||||
self._message = value
|
||||
|
||||
def __repr__(self):
|
||||
return f'ResponseStatus(code={self.code}, message={self.message})'
|
||||
9
pico-client/classes/weather.py
Normal file
9
pico-client/classes/weather.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from .location import Location
|
||||
from .current_condition import CurrentCondition
|
||||
class Weather:
|
||||
def __init__(self, location: Location, current: CurrentCondition):
|
||||
self.location = location
|
||||
self.current = current
|
||||
|
||||
def __repr__(self):
|
||||
return f'Weather(condition={self.location}, current={self.current}'
|
||||
48
pico-client/classes/weather_response.py
Normal file
48
pico-client/classes/weather_response.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from .weather import Weather
|
||||
from .response_status import ResponseStatus
|
||||
|
||||
class WeatherResponse:
|
||||
_response_status: ResponseStatus
|
||||
_weather: Weather
|
||||
|
||||
def __init__(self):
|
||||
self._weather = None
|
||||
self._response_status = None
|
||||
|
||||
# Weather property with getter and setter
|
||||
@property
|
||||
def weather(self)->Weather:
|
||||
"""Get the weather data"""
|
||||
return self._weather
|
||||
|
||||
@weather.setter
|
||||
def weather(self, value:Weather)->None:
|
||||
"""Set the weather data with validation"""
|
||||
if value is not None and not isinstance(value, Weather):
|
||||
raise TypeError("weather must be an instance of Weather class")
|
||||
self._weather = value
|
||||
|
||||
# ResponseStatus property with getter and setter
|
||||
@property
|
||||
def response_status(self)->ResponseStatus:
|
||||
"""Get the response status"""
|
||||
return self._response_status
|
||||
|
||||
@response_status.setter
|
||||
def response_status(self, value:ResponseStatus)->None:
|
||||
"""Set the response status with validation"""
|
||||
if value is not None and not isinstance(value, ResponseStatus):
|
||||
raise TypeError("response_status must be an instance of ResponseStatus class")
|
||||
self._response_status = value
|
||||
|
||||
# Additional utility methods
|
||||
def is_successful(self)->bool:
|
||||
"""Check if the response was successful"""
|
||||
return self._response_status is not None
|
||||
|
||||
def has_weather_data(self)->bool:
|
||||
"""Check if weather data is available"""
|
||||
return self._weather is not None
|
||||
|
||||
def __str__(self)->str:
|
||||
return f"WeatherResponse(weather={self._weather}, status={self._response_status})"
|
||||
Reference in New Issue
Block a user