From 43e6647ed120de8b7bf0c3beadf580fbf2f5b698 Mon Sep 17 00:00:00 2001 From: Marco Gosselink Date: Thu, 7 Mar 2024 20:41:20 +0100 Subject: [PATCH] Fixed display precision for rain values and dropped Vantage Vue due to uncertain operation --- README.md | 2 ++ custom_components/davis_vantage/__init__.py | 6 ++--- custom_components/davis_vantage/client.py | 27 +++++++++++++++++-- .../davis_vantage/config_flow.py | 2 +- custom_components/davis_vantage/const.py | 3 +-- custom_components/davis_vantage/sensor.py | 10 +++---- 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 325b25f..c17bd30 100755 --- a/README.md +++ b/README.md @@ -157,3 +157,5 @@ The entity information is updated every 30 seconds (default or other value is ch During first setup the communication to the weather station can be a bit tricky, resulting in an error saying the device didn't communicate. Please try again to set it up (can take up to 5 times). If Wind Gust doesn't show a value or "Unknown" make sure the Davis time is set correctly. You can check this by using service "Davis Vantage: Get Davis Time" and, if necessary, correct it by using service "Davis Vantage: Set Davis Time". + +It's unsure if Vantage Vue is working. Please contact me if this integration is working so I can add it again. diff --git a/custom_components/davis_vantage/__init__.py b/custom_components/davis_vantage/__init__.py index b215694..8bac341 100755 --- a/custom_components/davis_vantage/__init__.py +++ b/custom_components/davis_vantage/__init__.py @@ -54,9 +54,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: client = DavisVantageClient(hass, protocol, link, rain_collector) await client.connect_to_station() - info = await client.async_get_info() - firmware_version = info.get('version', None) if info is not None else None - hass.data.setdefault(DATA_ARCHIVE_PERIOD, info.get('archive_period', None) if info is not None else None) + static_info = await client.async_get_static_info() + firmware_version = static_info.get('version', None) if static_info is not None else None + hass.data.setdefault(DATA_ARCHIVE_PERIOD, static_info.get('archive_period', None) if static_info is not None else None) device_info = DeviceInfo( identifiers={(DOMAIN, entry.entry_id)}, diff --git a/custom_components/davis_vantage/client.py b/custom_components/davis_vantage/client.py index ed276f9..ed529d1 100755 --- a/custom_components/davis_vantage/client.py +++ b/custom_components/davis_vantage/client.py @@ -93,7 +93,7 @@ def get_current_data( try: end_datetime = datetime.now() - start_datetime = end_datetime - timedelta(minutes=(self._vantagepro2.archive_period * 2)) # type: ignore + start_datetime = end_datetime - timedelta(minutes=(self._hass.data.get(DATA_ARCHIVE_PERIOD) * 2)) # type: ignore archives = self._vantagepro2.get_archives(start_datetime, end_datetime) except Exception: pass @@ -209,9 +209,9 @@ def get_info(self) -> dict[str, Any] | None: try: self._vantagepro2.link.open() firmware_version = self._vantagepro2.firmware_version # type: ignore + archive_period = self._vantagepro2.archive_period # type: ignore firmware_date = self._vantagepro2.firmware_date # type: ignore diagnostics = self._vantagepro2.diagnostics # type: ignore - archive_period = self._vantagepro2.archive_period # type: ignore except Exception as e: raise e finally: @@ -232,6 +232,29 @@ async def async_get_info(self) -> dict[str, Any] | None: _LOGGER.error("Couldn't get firmware info: %s", e) return info + def get_static_info(self) -> dict[str, Any] | None: + try: + self._vantagepro2.link.open() + firmware_version = self._vantagepro2.firmware_version # type: ignore + archive_period = self._vantagepro2.archive_period # type: ignore + except Exception as e: + raise e + finally: + self._vantagepro2.link.close() + return { + "version": firmware_version, + "archive_period": archive_period + } + + async def async_get_static_info(self) -> dict[str, Any] | None: + info = None + try: + loop = asyncio.get_event_loop() + info = await loop.run_in_executor(None, self.get_static_info) + except Exception as e: + _LOGGER.error("Couldn't get static info: %s", e) + return info + def add_additional_info(self, data: dict[str, Any]) -> None: if data["TempOut"] is not None: if data["HumOut"] is not None: diff --git a/custom_components/davis_vantage/config_flow.py b/custom_components/davis_vantage/config_flow.py index f3d86c5..5c89035 100755 --- a/custom_components/davis_vantage/config_flow.py +++ b/custom_components/davis_vantage/config_flow.py @@ -150,7 +150,7 @@ async def async_step_setup_other_info( list_of_station_models = [ MODEL_VANTAGE_PRO2, MODEL_VANTAGE_PRO2PLUS, - MODEL_VANTAGE_VUE + # MODEL_VANTAGE_VUE ] STEP_USER_DATA_SCHEMA = vol.Schema( { diff --git a/custom_components/davis_vantage/const.py b/custom_components/davis_vantage/const.py index bfc82b6..7a32104 100755 --- a/custom_components/davis_vantage/const.py +++ b/custom_components/davis_vantage/const.py @@ -3,8 +3,7 @@ NAME = "Davis Vantage" DOMAIN = "davis_vantage" MANUFACTURER = "Davis" -MODEL = "Vantage Pro2/Vue" -VERSION = "1.1.12" +VERSION = "1.1.13" DEFAULT_SYNC_INTERVAL = 30 # seconds DEFAULT_NAME = NAME diff --git a/custom_components/davis_vantage/sensor.py b/custom_components/davis_vantage/sensor.py index 79f7f9b..6113092 100755 --- a/custom_components/davis_vantage/sensor.py +++ b/custom_components/davis_vantage/sensor.py @@ -328,7 +328,7 @@ def get_sensor_descriptions(model: str) -> list[SensorEntityDescription]: device_class=SensorDeviceClass.PRECIPITATION, state_class="measurement", native_unit_of_measurement=UnitOfLength.INCHES, - suggested_display_precision=1 + suggested_display_precision=2 ), SensorEntityDescription( key="RainMonth", @@ -337,7 +337,7 @@ def get_sensor_descriptions(model: str) -> list[SensorEntityDescription]: state_class="measurement", device_class=SensorDeviceClass.PRECIPITATION, native_unit_of_measurement=UnitOfLength.INCHES, - suggested_display_precision=1 + suggested_display_precision=2 ), SensorEntityDescription( key="RainYear", @@ -346,7 +346,7 @@ def get_sensor_descriptions(model: str) -> list[SensorEntityDescription]: state_class="measurement", device_class=SensorDeviceClass.PRECIPITATION, native_unit_of_measurement=UnitOfLength.INCHES, - suggested_display_precision=1 + suggested_display_precision=2 ), SensorEntityDescription( key="RainRate", @@ -355,7 +355,7 @@ def get_sensor_descriptions(model: str) -> list[SensorEntityDescription]: device_class=SensorDeviceClass.PRECIPITATION_INTENSITY, state_class="measurement", native_unit_of_measurement=UnitOfVolumetricFlux.INCHES_PER_HOUR, - suggested_display_precision=1 + suggested_display_precision=2 ), SensorEntityDescription( key="RainRateDay", @@ -364,7 +364,7 @@ def get_sensor_descriptions(model: str) -> list[SensorEntityDescription]: device_class=SensorDeviceClass.PRECIPITATION_INTENSITY, state_class="measurement", native_unit_of_measurement=UnitOfVolumetricFlux.INCHES_PER_HOUR, - suggested_display_precision=1 + suggested_display_precision=2 ), SensorEntityDescription( key="RainRateTime",