Skip to content

Commit

Permalink
Fixed display precision for rain values and dropped Vantage Vue due t…
Browse files Browse the repository at this point in the history
…o uncertain operation
  • Loading branch information
MarcoGos committed Mar 7, 2024
1 parent ea7def9 commit 43e6647
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 3 additions & 3 deletions custom_components/davis_vantage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
27 changes: 25 additions & 2 deletions custom_components/davis_vantage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/davis_vantage/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
3 changes: 1 addition & 2 deletions custom_components/davis_vantage/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions custom_components/davis_vantage/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 43e6647

Please sign in to comment.