Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions homeassistant/components/lamarzocco/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
}
},
"number": {
"bbw_dose": {
"default": "mdi:weight-gram"
},
"coffee_temp": {
"default": "mdi:thermometer-water"
},
Expand All @@ -51,6 +54,14 @@
}
},
"select": {
"bbw_dose_mode": {
"default": "mdi:all-inclusive-box",
"state": {
"continuous": "mdi:all-inclusive-box",
"dose1": "mdi:numeric-1-box",
"dose2": "mdi:numeric-2-box"
}
},
"prebrew_infusion_select": {
"default": "mdi:water-pump-off",
"state": {
Expand Down
76 changes: 74 additions & 2 deletions homeassistant/components/lamarzocco/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
from typing import Any, cast

from pylamarzocco import LaMarzoccoMachine
from pylamarzocco.const import ModelName, PreExtractionMode, WidgetType
from pylamarzocco.const import DoseMode, ModelName, PreExtractionMode, WidgetType
from pylamarzocco.exceptions import RequestNotSuccessful
from pylamarzocco.models import CoffeeBoiler, PreBrewing, SteamBoilerTemperature
from pylamarzocco.models import (
BrewByWeightDoses,
CoffeeBoiler,
PreBrewing,
SteamBoilerTemperature,
)

from homeassistant.components.number import (
NumberDeviceClass,
Expand All @@ -18,6 +23,7 @@
PRECISION_TENTHS,
PRECISION_WHOLE,
EntityCategory,
UnitOfMass,
UnitOfTemperature,
UnitOfTime,
)
Expand Down Expand Up @@ -219,6 +225,72 @@ class LaMarzoccoNumberEntityDescription(
)
),
),
LaMarzoccoNumberEntityDescription(
key="bbw_dose_1",
translation_key="bbw_dose",
translation_placeholders={"dose": "Dose 1"},
device_class=NumberDeviceClass.WEIGHT,
native_unit_of_measurement=UnitOfMass.GRAMS,
native_step=PRECISION_TENTHS,
native_min_value=5,
native_max_value=100,
entity_category=EntityCategory.CONFIG,
set_value_fn=(
lambda machine, value: machine.set_brew_by_weight_dose(
dose=DoseMode.DOSE_1,
value=value,
)
),
native_value_fn=(
lambda machine: cast(
BrewByWeightDoses,
machine.dashboard.config[WidgetType.CM_BREW_BY_WEIGHT_DOSES],
).doses.dose_1.dose
),
available_fn=lambda coordinator: (
cast(
BrewByWeightDoses,
coordinator.device.dashboard.config[WidgetType.CM_BREW_BY_WEIGHT_DOSES],
).scale_connected
),
supported_fn=(
lambda coordinator: coordinator.device.dashboard.model_name
in (ModelName.LINEA_MINI, ModelName.LINEA_MINI_R)
),
),
LaMarzoccoNumberEntityDescription(
key="bbw_dose_2",
translation_key="bbw_dose",
translation_placeholders={"dose": "Dose 2"},
device_class=NumberDeviceClass.WEIGHT,
native_unit_of_measurement=UnitOfMass.GRAMS,
native_step=PRECISION_TENTHS,
native_min_value=5,
native_max_value=100,
entity_category=EntityCategory.CONFIG,
set_value_fn=(
lambda machine, value: machine.set_brew_by_weight_dose(
dose=DoseMode.DOSE_2,
value=value,
)
),
native_value_fn=(
lambda machine: cast(
BrewByWeightDoses,
machine.dashboard.config[WidgetType.CM_BREW_BY_WEIGHT_DOSES],
).doses.dose_2.dose
),
available_fn=lambda coordinator: (
cast(
BrewByWeightDoses,
coordinator.device.dashboard.config[WidgetType.CM_BREW_BY_WEIGHT_DOSES],
).scale_connected
),
supported_fn=(
lambda coordinator: coordinator.device.dashboard.model_name
in (ModelName.LINEA_MINI, ModelName.LINEA_MINI_R)
),
),
)


Expand Down
36 changes: 35 additions & 1 deletion homeassistant/components/lamarzocco/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any, cast

from pylamarzocco.const import (
DoseMode,
ModelName,
PreExtractionMode,
SmartStandByType,
Expand All @@ -13,7 +14,7 @@
)
from pylamarzocco.devices import LaMarzoccoMachine
from pylamarzocco.exceptions import RequestNotSuccessful
from pylamarzocco.models import PreBrewing, SteamBoilerLevel
from pylamarzocco.models import BrewByWeightDoses, PreBrewing, SteamBoilerLevel

from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.const import EntityCategory
Expand Down Expand Up @@ -50,6 +51,14 @@

STANDBY_MODE_LM_TO_HA = {value: key for key, value in STANDBY_MODE_HA_TO_LM.items()}

DOSE_MODE_HA_TO_LM = {
"continuous": DoseMode.CONTINUOUS,
"dose1": DoseMode.DOSE_1,
"dose2": DoseMode.DOSE_2,
}

DOSE_MODE_LM_TO_HA = {value: key for key, value in DOSE_MODE_HA_TO_LM.items()}


@dataclass(frozen=True, kw_only=True)
class LaMarzoccoSelectEntityDescription(
Expand Down Expand Up @@ -117,6 +126,31 @@ class LaMarzoccoSelectEntityDescription(
machine.schedule.smart_wake_up_sleep.smart_stand_by_after
],
),
LaMarzoccoSelectEntityDescription(
key="bbw_dose_mode",
translation_key="bbw_dose_mode",
entity_category=EntityCategory.CONFIG,
options=["continuous", "dose1", "dose2"],
select_option_fn=lambda machine, option: machine.set_brew_by_weight_dose_mode(
mode=DOSE_MODE_HA_TO_LM[option]
),
current_option_fn=lambda machine: DOSE_MODE_LM_TO_HA[
cast(
BrewByWeightDoses,
machine.dashboard.config[WidgetType.CM_BREW_BY_WEIGHT_DOSES],
).mode
],
available_fn=lambda coordinator: (
cast(
BrewByWeightDoses,
coordinator.device.dashboard.config[WidgetType.CM_BREW_BY_WEIGHT_DOSES],
).scale_connected
),
supported_fn=(
lambda coordinator: coordinator.device.dashboard.model_name
in (ModelName.LINEA_MINI, ModelName.LINEA_MINI_R)
),
),
)


Expand Down
11 changes: 11 additions & 0 deletions homeassistant/components/lamarzocco/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
}
},
"number": {
"bbw_dose": {
"name": "Brew by weight {dose}"
},
"coffee_temp": {
"name": "Coffee target temperature"
},
Expand All @@ -107,6 +110,14 @@
}
},
"select": {
"bbw_dose_mode": {
"name": "Brew by weight dose mode",
"state": {
"continuous": "Continuous",
"dose1": "Dose 1",
"dose2": "Dose 2"
}
},
"prebrew_infusion_select": {
"name": "Prebrew/-infusion mode",
"state": {
Expand Down
2 changes: 1 addition & 1 deletion tests/components/lamarzocco/fixtures/config_mini.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"code": "CMBrewByWeightDoses",
"index": 1,
"output": {
"scaleConnected": false,
"scaleConnected": true,
"availableModes": ["Continuous"],
"mode": "Continuous",
"doses": {
Expand Down
118 changes: 118 additions & 0 deletions tests/components/lamarzocco/snapshots/test_number.ambr
Original file line number Diff line number Diff line change
@@ -1,4 +1,122 @@
# serializer version: 1
# name: test_brew_by_weight_dose[Linea Mini][entry-dose-1]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'max': 100,
'min': 5,
'mode': <NumberMode.AUTO: 'auto'>,
'step': 0.1,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'number',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'number.lm012345_brew_by_weight_dose_1',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <NumberDeviceClass.WEIGHT: 'weight'>,
'original_icon': None,
'original_name': 'Brew by weight Dose 1',
'platform': 'lamarzocco',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'bbw_dose',
'unique_id': 'LM012345_bbw_dose_1',
'unit_of_measurement': <UnitOfMass.GRAMS: 'g'>,
})
# ---
# name: test_brew_by_weight_dose[Linea Mini][entry-dose-2]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'max': 100,
'min': 5,
'mode': <NumberMode.AUTO: 'auto'>,
'step': 0.1,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'number',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'number.lm012345_brew_by_weight_dose_2',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <NumberDeviceClass.WEIGHT: 'weight'>,
'original_icon': None,
'original_name': 'Brew by weight Dose 2',
'platform': 'lamarzocco',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'bbw_dose',
'unique_id': 'LM012345_bbw_dose_2',
'unit_of_measurement': <UnitOfMass.GRAMS: 'g'>,
})
# ---
# name: test_brew_by_weight_dose[Linea Mini][state-dose-1]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'weight',
'friendly_name': 'LM012345 Brew by weight Dose 1',
'max': 100,
'min': 5,
'mode': <NumberMode.AUTO: 'auto'>,
'step': 0.1,
'unit_of_measurement': <UnitOfMass.GRAMS: 'g'>,
}),
'context': <ANY>,
'entity_id': 'number.lm012345_brew_by_weight_dose_1',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '34.5',
})
# ---
# name: test_brew_by_weight_dose[Linea Mini][state-dose-2]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'weight',
'friendly_name': 'LM012345 Brew by weight Dose 2',
'max': 100,
'min': 5,
'mode': <NumberMode.AUTO: 'auto'>,
'step': 0.1,
'unit_of_measurement': <UnitOfMass.GRAMS: 'g'>,
}),
'context': <ANY>,
'entity_id': 'number.lm012345_brew_by_weight_dose_2',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '17.5',
})
# ---
# name: test_general_numbers[coffee_target_temperature-94-set_coffee_target_temperature-kwargs0]
StateSnapshot({
'attributes': ReadOnlyDict({
Expand Down
Loading
Loading