From a661e08ab0cde02ef34be1e669ea53513b468015 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Fri, 10 May 2024 17:35:11 -0700 Subject: [PATCH] Fixes for optional fields after mashumaro conversion --- pyrainbird/data.py | 54 +++++++++++++++++++------------------- tests/test_async_client.py | 28 ++++++++++++++++++++ 2 files changed, 55 insertions(+), 27 deletions(-) diff --git a/pyrainbird/data.py b/pyrainbird/data.py index 0113698..abadd52 100644 --- a/pyrainbird/data.py +++ b/pyrainbird/data.py @@ -195,20 +195,20 @@ class WaterBudget: class WifiParams(DataClassDictMixin): """Wifi parameters for the device.""" - mac_address: Optional[str] = field(metadata=field_options(alias="macAddress")) + mac_address: Optional[str] = field(metadata=field_options(alias="macAddress"), default=None) """The mac address for the device, also referred to as the stick id.""" - local_ip_address: Optional[str] = field(metadata=field_options(alias="localIpAddress")) - local_netmask: Optional[str] = field(metadata=field_options(alias="localNetmask")) - local_gateway: Optional[str] = field(metadata=field_options(alias="localGateway")) - rssi: Optional[int] - wifi_ssid: Optional[str] = field(metadata=field_options(alias="wifiSsid")) - wifi_password: Optional[str] = field(metadata=field_options(alias="wifiPassword")) - wifi_security: Optional[str] = field(metadata=field_options(alias="wifiSecurity")) - ap_timeout_no_lan: Optional[int] = field(metadata=field_options(alias="apTimeoutNoLan")) - ap_timeout_idle: Optional[int] = field(metadata=field_options(alias="apTimeoutIdle")) - ap_security: Optional[str] = field(metadata=field_options(alias="apSecurity")) - sick_version: Optional[str] = field(metadata=field_options(alias="stickVersion")) + local_ip_address: Optional[str] = field(metadata=field_options(alias="localIpAddress"), default=None) + local_netmask: Optional[str] = field(metadata=field_options(alias="localNetmask"), default=None) + local_gateway: Optional[str] = field(metadata=field_options(alias="localGateway"), default=None) + rssi: Optional[int] = None + wifi_ssid: Optional[str] = field(metadata=field_options(alias="wifiSsid"), default=None) + wifi_password: Optional[str] = field(metadata=field_options(alias="wifiPassword"), default=None) + wifi_security: Optional[str] = field(metadata=field_options(alias="wifiSecurity"), default=None) + ap_timeout_no_lan: Optional[int] = field(metadata=field_options(alias="apTimeoutNoLan"), default=None) + ap_timeout_idle: Optional[int] = field(metadata=field_options(alias="apTimeoutIdle"), default=None) + ap_security: Optional[str] = field(metadata=field_options(alias="apSecurity"), default=None) + sick_version: Optional[str] = field(metadata=field_options(alias="stickVersion"), default=None) class SoilType(IntEnum): @@ -246,10 +246,10 @@ class Settings(DataClassDictMixin): program_opt_out_mask: str = field(metadata=field_options(alias="programOptOutMask")) global_disable: bool = field(metadata=field_options(alias="globalDisable")) - code: Optional[str] + code: Optional[str] = None """Zip code for the device.""" - country: Optional[str] + country: Optional[str] = None """Country location of the device.""" # Program information @@ -277,10 +277,10 @@ class WeatherAdjustmentMask(DataClassDictMixin): class ZipCode(DataClassDictMixin): """Get the zip code of the device.""" - code: Optional[str] + code: Optional[str] = None """Zip code for the device.""" - country: Optional[str] + country: Optional[str] = None """Country location of the device.""" @@ -330,19 +330,19 @@ class Forecast(DataClassDictMixin): """Weather forecast data from the cloud API.""" date_time: Optional[int] = field(metadata=field_options(alias="dateTime")) - icon: Optional[str] - description: Optional[str] - high: Optional[int] - low: Optional[int] - chance_of_rain: Optional[int] - precip: Optional[float] + icon: Optional[str] = None + description: Optional[str] = None + high: Optional[int] = None + low: Optional[int] = None + chance_of_rain: Optional[int] = None + precip: Optional[float] = None @dataclass class Weather(DataClassDictMixin): """Weather settings from the cloud API.""" - city: Optional[str] + city: Optional[str] = None forecast: list[Forecast] = field(default_factory=list) location: Optional[str] = None time_zone_id: Optional[str] = field(metadata=field_options(alias="timeZoneId"), default=None) @@ -353,10 +353,10 @@ class Weather(DataClassDictMixin): class WeatherAndStatus(DataClassDictMixin): """Weather and status from the cloud API.""" - stick_id: Optional[str] = field(metadata=field_options(alias="StickId")) - controller: Optional[Controller] = field(metadata=field_options(alias="Controller")) - forecasted_rain: Optional[dict[str, Any]] = field(metadata=field_options(alias="ForecastedRain")) - weather: Optional[Weather] = field(metadata=field_options(alias="Weather")) + stick_id: Optional[str] = field(metadata=field_options(alias="StickId"), default=None) + controller: Optional[Controller] = field(metadata=field_options(alias="Controller"), default=None) + forecasted_rain: Optional[dict[str, Any]] = field(metadata=field_options(alias="ForecastedRain"), default=None) + weather: Optional[Weather] = field(metadata=field_options(alias="Weather"), default=None) @dataclass diff --git a/tests/test_async_client.py b/tests/test_async_client.py index e1c0b86..3436e26 100644 --- a/tests/test_async_client.py +++ b/tests/test_async_client.py @@ -491,6 +491,34 @@ async def test_get_wifi_params( } +async def test_get_wifi_params_optional_fields( + rainbird_controller: Callable[[], Awaitable[AsyncRainbirdController]], + encrypt_response: ResponseResult, +) -> None: + controller = await rainbird_controller() + payload = { + "jsonrpc": "2.0", + "result": {}, + "id": 1234, + } + encrypt_response(payload) + params = await controller.get_wifi_params() + assert params.to_dict() == { + "ap_security": None, + "ap_timeout_idle": None, + "ap_timeout_no_lan":None, + "local_gateway": None, + "local_ip_address": None, + "local_netmask": None, + "mac_address": None, + "rssi": None, + "sick_version": None, + "wifi_password": None, + "wifi_security": None, + "wifi_ssid": None, + } + + async def test_get_schedule_and_settings( rainbird_controller: Callable[[], Awaitable[AsyncRainbirdController]], response: ResponseResult,