Skip to content

Commit

Permalink
New BMW sensor for climate activity (home-assistant#110287)
Browse files Browse the repository at this point in the history
* add sensor with climate activity status

* Update strings.json

* use icon translation and is_available for sensor

* use enum with translations

* Return None if value is UNKNOWN

* fix getting the value: x.value

* fix getting the value: x instead of x.value

* Fix tests and pre-commit

---------

Co-authored-by: Richard <rikroe@users.noreply.github.com>
  • Loading branch information
brave0d and rikroe authored Apr 16, 2024
1 parent c5c407b commit a99ecb0
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
7 changes: 7 additions & 0 deletions homeassistant/components/bmw_connected_drive/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@
"north_america": 600,
"rest_of_world": 300,
}

CLIMATE_ACTIVITY_STATE: list[str] = [
"cooling",
"heating",
"inactive",
"standby",
]
3 changes: 3 additions & 0 deletions homeassistant/components/bmw_connected_drive/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
},
"remaining_fuel_percent": {
"default": "mdi:gas-station"
},
"climate_status": {
"default": "mdi:fan"
}
},
"switch": {
Expand Down
11 changes: 10 additions & 1 deletion homeassistant/components/bmw_connected_drive/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from homeassistant.helpers.typing import StateType

from . import BMWBaseEntity
from .const import DOMAIN, UNIT_MAP
from .const import CLIMATE_ACTIVITY_STATE, DOMAIN, UNIT_MAP
from .coordinator import BMWDataUpdateCoordinator

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -153,6 +153,15 @@ def convert_and_round(
state_class=SensorStateClass.MEASUREMENT,
is_available=lambda v: v.is_lsc_enabled and v.has_combustion_drivetrain,
),
BMWSensorEntityDescription(
key="activity",
translation_key="climate_status",
key_class="climate",
device_class=SensorDeviceClass.ENUM,
options=CLIMATE_ACTIVITY_STATE,
value=lambda x, _: x.lower() if x != "UNKNOWN" else None,
is_available=lambda v: v.is_remote_climate_stop_enabled,
),
]


Expand Down
9 changes: 9 additions & 0 deletions homeassistant/components/bmw_connected_drive/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@
},
"remaining_fuel_percent": {
"name": "Remaining fuel percent"
},
"climate_status": {
"name": "Climate status",
"state": {
"cooling": "Cooling",
"heating": "Heating",
"inactive": "Inactive",
"standby": "Standby"
}
}
},
"switch": {
Expand Down
57 changes: 57 additions & 0 deletions tests/components/bmw_connected_drive/snapshots/test_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@
'last_updated': <ANY>,
'state': '340',
}),
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by MyBMW',
'device_class': 'enum',
'friendly_name': 'iX xDrive50 Climate status',
'options': list([
'cooling',
'heating',
'inactive',
'standby',
]),
}),
'context': <ANY>,
'entity_id': 'sensor.ix_xdrive50_climate_status',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'inactive',
}),
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by MyBMW',
Expand Down Expand Up @@ -191,6 +210,25 @@
'last_updated': <ANY>,
'state': '472',
}),
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by MyBMW',
'device_class': 'enum',
'friendly_name': 'i4 eDrive40 Climate status',
'options': list([
'cooling',
'heating',
'inactive',
'standby',
]),
}),
'context': <ANY>,
'entity_id': 'sensor.i4_edrive40_climate_status',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'heating',
}),
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by MyBMW',
Expand Down Expand Up @@ -261,6 +299,25 @@
'last_updated': <ANY>,
'state': '80',
}),
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by MyBMW',
'device_class': 'enum',
'friendly_name': 'M340i xDrive Climate status',
'options': list([
'cooling',
'heating',
'inactive',
'standby',
]),
}),
'context': <ANY>,
'entity_id': 'sensor.m340i_xdrive_climate_status',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'inactive',
}),
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by MyBMW',
Expand Down

0 comments on commit a99ecb0

Please sign in to comment.