Skip to content

Commit

Permalink
Add diagnostics to La Marzocco (home-assistant#108240)
Browse files Browse the repository at this point in the history
* add diagnostics

* make firmware section easier to read
  • Loading branch information
zweckj authored Jan 18, 2024
1 parent 3761d13 commit 83e0a75
Show file tree
Hide file tree
Showing 3 changed files with 366 additions and 0 deletions.
44 changes: 44 additions & 0 deletions homeassistant/components/lamarzocco/diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Diagnostics support for La Marzocco."""


from __future__ import annotations

from typing import Any

from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant

from .const import DOMAIN
from .coordinator import LaMarzoccoUpdateCoordinator

TO_REDACT = {
"serial_number",
"machine_sn",
}


async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
coordinator: LaMarzoccoUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
# collect all data sources
data = {}
data["current_status"] = coordinator.lm.current_status
data["machine_info"] = coordinator.lm.machine_info
data["config"] = coordinator.lm.config
data["statistics"] = {"stats": coordinator.lm.statistics} # wrap to satisfy mypy

# build a firmware section
data["firmware"] = {
"machine": {
"version": coordinator.lm.firmware_version,
"latest_version": coordinator.lm.latest_firmware_version,
},
"gateway": {
"version": coordinator.lm.gateway_version,
"latest_version": coordinator.lm.latest_gateway_version,
},
}
return async_redact_data(data, TO_REDACT)
301 changes: 301 additions & 0 deletions tests/components/lamarzocco/snapshots/test_diagnostics.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
# serializer version: 1
# name: test_diagnostics
dict({
'config': dict({
'boilerTargetTemperature': dict({
'CoffeeBoiler1': 95,
'SteamBoiler': 123.9000015258789,
}),
'boilers': list([
dict({
'current': 123.80000305175781,
'id': 'SteamBoiler',
'isEnabled': True,
'target': 123.9000015258789,
}),
dict({
'current': 96.5,
'id': 'CoffeeBoiler1',
'isEnabled': True,
'target': 95,
}),
]),
'clock': '1901-07-08T10:29:00',
'firmwareVersions': list([
dict({
'fw_version': '1.40',
'name': 'machine_firmware',
}),
dict({
'fw_version': 'v3.1-rc4',
'name': 'gateway_firmware',
}),
]),
'groupCapabilities': list([
dict({
'capabilities': dict({
'boilerId': 'CoffeeBoiler1',
'groupNumber': 'Group1',
'groupType': 'AV_Group',
'hasFlowmeter': True,
'hasScale': False,
'numberOfDoses': 4,
}),
'doseMode': dict({
'brewingType': 'PulsesType',
'groupNumber': 'Group1',
}),
'doses': list([
dict({
'doseIndex': 'DoseA',
'doseType': 'PulsesType',
'groupNumber': 'Group1',
'stopTarget': 135,
}),
dict({
'doseIndex': 'DoseB',
'doseType': 'PulsesType',
'groupNumber': 'Group1',
'stopTarget': 97,
}),
dict({
'doseIndex': 'DoseC',
'doseType': 'PulsesType',
'groupNumber': 'Group1',
'stopTarget': 108,
}),
dict({
'doseIndex': 'DoseD',
'doseType': 'PulsesType',
'groupNumber': 'Group1',
'stopTarget': 121,
}),
]),
}),
]),
'isBackFlushEnabled': False,
'isPlumbedIn': True,
'machineCapabilities': list([
dict({
'coffeeBoilersNumber': 1,
'family': 'GS3AV',
'groupsNumber': 1,
'hasCupWarmer': False,
'machineModes': list([
'BrewingMode',
'StandBy',
]),
'schedulingType': 'weeklyScheduling',
'steamBoilersNumber': 1,
'teaDosesNumber': 1,
}),
]),
'machineMode': 'BrewingMode',
'machine_hw': '2',
'machine_sn': '**REDACTED**',
'preinfusionMode': dict({
'Group1': dict({
'groupNumber': 'Group1',
'preinfusionStyle': 'PreinfusionByDoseType',
}),
}),
'preinfusionModesAvailable': list([
'ByDoseType',
]),
'preinfusionSettings': dict({
'Group1': list([
dict({
'doseType': 'DoseA',
'groupNumber': 'Group1',
'preWetHoldTime': 1,
'preWetTime': 0.5,
}),
dict({
'doseType': 'DoseB',
'groupNumber': 'Group1',
'preWetHoldTime': 1,
'preWetTime': 0.5,
}),
dict({
'doseType': 'DoseC',
'groupNumber': 'Group1',
'preWetHoldTime': 3.299999952316284,
'preWetTime': 3.299999952316284,
}),
dict({
'doseType': 'DoseD',
'groupNumber': 'Group1',
'preWetHoldTime': 2,
'preWetTime': 2,
}),
]),
'mode': 'TypeB',
}),
'standByTime': 0,
'tankStatus': True,
'teaDoses': dict({
'DoseA': dict({
'doseIndex': 'DoseA',
'stopTarget': 8,
}),
}),
'version': 'v1',
'weeklySchedulingConfig': dict({
'enabled': True,
'friday': dict({
'enabled': True,
'h_off': 16,
'h_on': 6,
'm_off': 0,
'm_on': 0,
}),
'monday': dict({
'enabled': True,
'h_off': 16,
'h_on': 6,
'm_off': 0,
'm_on': 0,
}),
'saturday': dict({
'enabled': True,
'h_off': 16,
'h_on': 6,
'm_off': 0,
'm_on': 0,
}),
'sunday': dict({
'enabled': True,
'h_off': 16,
'h_on': 6,
'm_off': 0,
'm_on': 0,
}),
'thursday': dict({
'enabled': True,
'h_off': 16,
'h_on': 6,
'm_off': 0,
'm_on': 0,
}),
'tuesday': dict({
'enabled': True,
'h_off': 16,
'h_on': 6,
'm_off': 0,
'm_on': 0,
}),
'wednesday': dict({
'enabled': True,
'h_off': 16,
'h_on': 6,
'm_off': 0,
'm_on': 0,
}),
}),
}),
'current_status': dict({
'brew_active': False,
'coffee_boiler_on': True,
'coffee_set_temp': 95,
'coffee_temp': 93,
'dose_k1': 1023,
'dose_k2': 1023,
'dose_k3': 1023,
'dose_k4': 1023,
'dose_k5': 1023,
'drinks_k1': 13,
'drinks_k2': 2,
'drinks_k3': 42,
'drinks_k4': 34,
'enable_prebrewing': True,
'enable_preinfusion': False,
'fri_auto': 'Disabled',
'fri_off_time': '00:00',
'fri_on_time': '00:00',
'global_auto': 'Enabled',
'mon_auto': 'Disabled',
'mon_off_time': '00:00',
'mon_on_time': '00:00',
'power': True,
'prebrewing_toff_k1': 5,
'prebrewing_toff_k2': 5,
'prebrewing_toff_k3': 5,
'prebrewing_toff_k4': 5,
'prebrewing_toff_k5': 5,
'prebrewing_ton_k1': 3,
'prebrewing_ton_k2': 3,
'prebrewing_ton_k3': 3,
'prebrewing_ton_k4': 3,
'prebrewing_ton_k5': 3,
'preinfusion_k1': 4,
'preinfusion_k2': 4,
'preinfusion_k3': 4,
'preinfusion_k4': 4,
'preinfusion_k5': 4,
'sat_auto': 'Disabled',
'sat_off_time': '00:00',
'sat_on_time': '00:00',
'steam_boiler_enable': True,
'steam_boiler_on': True,
'steam_level_set': 3,
'steam_set_temp': 128,
'steam_temp': 113,
'sun_auto': 'Disabled',
'sun_off_time': '00:00',
'sun_on_time': '00:00',
'thu_auto': 'Disabled',
'thu_off_time': '00:00',
'thu_on_time': '00:00',
'total_flushing': 69,
'tue_auto': 'Disabled',
'tue_off_time': '00:00',
'tue_on_time': '00:00',
'water_reservoir_contact': True,
'wed_auto': 'Disabled',
'wed_off_time': '00:00',
'wed_on_time': '00:00',
}),
'firmware': dict({
'gateway': dict({
'latest_version': 'v3.1-rc4',
'version': 'v2.2-rc0',
}),
'machine': dict({
'latest_version': '1.2',
'version': '1.1',
}),
}),
'machine_info': dict({
'machine_name': 'GS01234',
'serial_number': '**REDACTED**',
}),
'statistics': dict({
'stats': list([
dict({
'coffeeType': 0,
'count': 1047,
}),
dict({
'coffeeType': 1,
'count': 560,
}),
dict({
'coffeeType': 2,
'count': 468,
}),
dict({
'coffeeType': 3,
'count': 312,
}),
dict({
'coffeeType': 4,
'count': 2252,
}),
dict({
'coffeeType': -1,
'count': 1740,
}),
]),
}),
})
# ---
21 changes: 21 additions & 0 deletions tests/components/lamarzocco/test_diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Tests for the diagnostics data provided by the La Marzocco integration."""
from syrupy import SnapshotAssertion

from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry
from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator


async def test_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
init_integration: MockConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test diagnostics."""
assert (
await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
== snapshot
)

0 comments on commit 83e0a75

Please sign in to comment.