v.0.7.0 WeatherResponse

This commit is contained in:
tiijay
2025-11-13 18:17:25 +01:00
parent d9fe55688d
commit 303a0f4468
8 changed files with 161 additions and 34 deletions

View File

@@ -1,4 +1,8 @@
from .weather import Weather, AirQuality, Condition, CurrentCondition
from .location import Location
from .response_status import ResponseStatus
from .weather_response import WeatherResponse
__all__ = ["Weather","AirQuality","Condition","CurrentCondition","Location"]
__all__ = ["Weather",
"AirQuality","Condition","CurrentCondition","Location",
"ResponseStatus","WeatherResponse"]

View 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})'

View File

@@ -0,0 +1,48 @@
from app.classes import Weather
from app.classes 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})"