Skip to content

Commit

Permalink
Added firmware information and service get_info
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGos committed Oct 20, 2023
1 parent 021500f commit ef7cac3
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 4 deletions.
22 changes: 20 additions & 2 deletions custom_components/davis_vantage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
MANUFACTURER,
SERVICE_SET_DAVIS_TIME,
SERVICE_GET_DAVIS_TIME,
SERVICE_GET_RAW_DATA
SERVICE_GET_RAW_DATA,
SERVICE_GET_INFO
)
from .coordinator import DavisVantageDataUpdateCoordinator
from .utils import convert_to_iso_datetime
Expand Down Expand Up @@ -47,12 +48,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data[DOMAIN]['interval'] = entry.data.get("interval", 30)

client = DavisVantageClient(hass, protocol, link, rain_collector, windrose8)
info = await client.async_get_info()
firmware_version = info.get('version', None) if info is not None else None

device_info = DeviceInfo(
identifiers={(DOMAIN, entry.entry_id)},
manufacturer=MANUFACTURER,
name=NAME,
model=VERSION
model=VERSION,
sw_version=firmware_version,
hw_version=None
)

hass.data[DOMAIN][entry.entry_id] = coordinator = DavisVantageDataUpdateCoordinator(
Expand Down Expand Up @@ -81,6 +86,15 @@ async def get_raw_data(call: ServiceCall) -> dict[str, Any]:
raw_data = client.get_raw_data()
json_data = safe_serialize(raw_data)
return json.loads(json_data)

async def get_info(call: ServiceCall) -> dict[str, Any]:
info = await client.async_get_info()
if info is not None:
return info
else:
return {
"error": "Couldn't get firmware information from Davis weather station"
}

hass.services.async_register(
DOMAIN, SERVICE_SET_DAVIS_TIME, set_davis_time
Expand All @@ -93,6 +107,10 @@ async def get_raw_data(call: ServiceCall) -> dict[str, Any]:
DOMAIN, SERVICE_GET_RAW_DATA, get_raw_data, supports_response=SupportsResponse.ONLY
)

hass.services.async_register(
DOMAIN, SERVICE_GET_INFO, get_info, supports_response=SupportsResponse.ONLY
)

def safe_serialize(obj: Any):
default = lambda o: f"<<non-serializable: {type(o).__qualname__}>>" # type: ignore
return json.dumps(obj, default=default) # type: ignore
Expand Down
Empty file modified custom_components/davis_vantage/assets/dark_icon.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified custom_components/davis_vantage/assets/[email protected]
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified custom_components/davis_vantage/assets/dark_logo.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified custom_components/davis_vantage/assets/icon.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified custom_components/davis_vantage/assets/[email protected]
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified custom_components/davis_vantage/assets/logo.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions custom_components/davis_vantage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ async def async_set_davis_time(self) -> None:
except Exception as e:
_LOGGER.error("Couldn't set davis time: %s", e)

def get_info(self) -> dict[str, Any] | None:
try:
self._vantagepro2.link.open()
firmware_version = self._vantagepro2.firmware_version # type: ignore
firmware_date = self._vantagepro2.firmware_date # type: ignore
diagnostics = self._vantagepro2.diagnostics # type: ignore
except Exception as e:
raise e
finally:
self._vantagepro2.link.close()
return { "version": firmware_version, "date": firmware_date, "diagnostics": diagnostics }

async def async_get_info(self) -> dict[str, Any] | None:
info = None
try:
loop = asyncio.get_event_loop()
info = await loop.run_in_executor(None, self.get_info)
except Exception as e:
_LOGGER.error("Couldn't get firmware 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
3 changes: 2 additions & 1 deletion custom_components/davis_vantage/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
DOMAIN = "davis_vantage"
MANUFACTURER = "Davis"
MODEL = "Vantage Pro2/Vue"
VERSION = "1.0.10"
VERSION = "1.0.11"

DEFAULT_SYNC_INTERVAL = 30 # seconds
DEFAULT_NAME = NAME
Expand All @@ -18,3 +18,4 @@
SERVICE_SET_DAVIS_TIME = 'set_davis_time'
SERVICE_GET_DAVIS_TIME = 'get_davis_time'
SERVICE_GET_RAW_DATA = 'get_raw_data'
SERVICE_GET_INFO = 'get_info'
4 changes: 3 additions & 1 deletion custom_components/davis_vantage/services.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ set_davis_time:
get_davis_time:
description: Get the time of the Davis weather station
get_raw_data:
description: Get the raw, unprocessed data from the last fetch
description: Get the raw, unprocessed data from the last fetch
get_firmware_info:
description: Get the firmware version and date information

0 comments on commit ef7cac3

Please sign in to comment.