diff --git a/custom_components/davis_vantage/client.py b/custom_components/davis_vantage/client.py index 24776e7..c781623 100755 --- a/custom_components/davis_vantage/client.py +++ b/custom_components/davis_vantage/client.py @@ -1,6 +1,7 @@ from typing import Any from datetime import datetime import logging +import asyncio from pyvantagepro import VantagePro2 from pyvantagepro.parser import LoopDataParserRevB @@ -34,7 +35,8 @@ async def async_get_current_data(self) -> LoopDataParserRevB | None: data = self._last_data try: self._vantagepro2.link.open() - new_data = self._vantagepro2.get_current_data() + loop = asyncio.get_event_loop() + new_data = await loop.run_in_executor(None, self._vantagepro2.get_current_data) if new_data: if contains_correct_data(new_data): self.add_additional_info(new_data) @@ -55,30 +57,27 @@ async def async_get_current_data(self) -> LoopDataParserRevB | None: async def async_get_davis_time(self) -> datetime | None: """Get time from weather station.""" + data = None try: self._vantagepro2.link.open() - data = self._vantagepro2.gettime() - self._vantagepro2.link.close() - return data + loop = asyncio.get_event_loop() + data = await loop.run_in_executor(None, self._vantagepro2.gettime) except Exception as e: - last_error = e + _LOGGER.error(f"Couldn't get davis time: {e}") finally: self._vantagepro2.link.close() - _LOGGER.error(f"Couldn't acquire data from {self.get_link()}: {last_error}") - return None + return data async def async_set_davis_time(self) -> None: """Set time of weather station.""" try: self._vantagepro2.link.open() - self._vantagepro2.settime(datetime.now()) - self._vantagepro2.link.close() - return + loop = asyncio.get_event_loop() + await loop.run_in_executor(None, self._vantagepro2.settime, datetime.now()) except Exception as e: - last_error = e + _LOGGER.error(f"Couldn't set davis time: {e}") finally: self._vantagepro2.link.close() - _LOGGER.error(f"Couldn't acquire data from {self.get_link()}: {last_error}") def add_additional_info(self, data: dict[str, Any]) -> None: data['HeatIndex'] = calc_heat_index(data['TempOut'], data['HumOut']) @@ -93,6 +92,7 @@ def convert_values(self, data: dict[str, Any]) -> None: data['Datetime'] = convert_to_iso_datetime(data['Datetime'], ZoneInfo(self._hass.config.time_zone)) data['BarTrend'] = get_baro_trend(data['BarTrend']) data['UV'] = get_uv(data['UV']) + data['SolarRad'] = get_solar_rad(data['SolarRad']) data['ForecastRuleNo'] = get_forecast_string(data['ForecastRuleNo']) data['RainCollector'] = self._rain_collector data['WindRoseSetup'] = 8 if self._windrose8 else 16 diff --git a/custom_components/davis_vantage/const.py b/custom_components/davis_vantage/const.py index fe5c74a..ee42095 100755 --- a/custom_components/davis_vantage/const.py +++ b/custom_components/davis_vantage/const.py @@ -4,7 +4,7 @@ DOMAIN = "davis_vantage" MANUFACTURER = "Davis" MODEL = "Vantage Pro2/Vue" -VERSION = "1.0.7" +VERSION = "1.0.8" DEFAULT_SYNC_INTERVAL = 30 # seconds DEFAULT_NAME = NAME diff --git a/custom_components/davis_vantage/utils.py b/custom_components/davis_vantage/utils.py index e498825..bea88d2 100755 --- a/custom_components/davis_vantage/utils.py +++ b/custom_components/davis_vantage/utils.py @@ -365,15 +365,15 @@ def get_forecast_string(wrule: int) -> str: wrule = 194 return ForecastStrings[wrule] -def get_uv(value: int) -> float|bool: +def get_uv(value: int) -> float: if value == 255: - return False + return None else: return round(value / 10, 1) -def get_solar_rad(value: int) -> float|bool: +def get_solar_rad(value: int) -> float: if value == 32767: - return False + return None else: return value