Skip to content

Commit

Permalink
Properly report cover positions to prometheus
Browse files Browse the repository at this point in the history
This component was using the attributes for setting position and tilt
instead of the attributes for getting them, resulting in no metrics. See
https://developers.home-assistant.io/docs/core/entity/cover/#properties.
  • Loading branch information
agoode committed Feb 10, 2024
1 parent 845071f commit 32953fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions homeassistant/components/prometheus/__init__.py
Expand Up @@ -21,7 +21,10 @@
ATTR_TARGET_TEMP_LOW,
HVACAction,
)
from homeassistant.components.cover import ATTR_POSITION, ATTR_TILT_POSITION
from homeassistant.components.cover import (
ATTR_CURRENT_POSITION,
ATTR_CURRENT_TILT_POSITION,
)
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.humidifier import ATTR_AVAILABLE_MODES, ATTR_HUMIDITY
from homeassistant.components.light import ATTR_BRIGHTNESS
Expand Down Expand Up @@ -437,7 +440,7 @@ def _handle_cover(self, state: State) -> None:
float(cover_state == state.state)
)

position = state.attributes.get(ATTR_POSITION)
position = state.attributes.get(ATTR_CURRENT_POSITION)
if position is not None:
position_metric = self._metric(
"cover_position",
Expand All @@ -446,7 +449,7 @@ def _handle_cover(self, state: State) -> None:
)
position_metric.labels(**self._labels(state)).set(float(position))

tilt_position = state.attributes.get(ATTR_TILT_POSITION)
tilt_position = state.attributes.get(ATTR_CURRENT_TILT_POSITION)
if tilt_position is not None:
tilt_position_metric = self._metric(
"cover_tilt_position",
Expand Down
4 changes: 2 additions & 2 deletions tests/components/prometheus/test_init.py
Expand Up @@ -1352,7 +1352,7 @@ async def cover_fixture(
suggested_object_id="position_shade",
original_name="Position Shade",
)
cover_position_attributes = {cover.ATTR_POSITION: 50}
cover_position_attributes = {cover.ATTR_CURRENT_POSITION: 50}
set_state_with_entry(hass, cover_position, STATE_OPEN, cover_position_attributes)
data["cover_position"] = cover_position

Expand All @@ -1363,7 +1363,7 @@ async def cover_fixture(
suggested_object_id="tilt_position_shade",
original_name="Tilt Position Shade",
)
cover_tilt_position_attributes = {cover.ATTR_TILT_POSITION: 50}
cover_tilt_position_attributes = {cover.ATTR_CURRENT_TILT_POSITION: 50}
set_state_with_entry(
hass, cover_tilt_position, STATE_OPEN, cover_tilt_position_attributes
)
Expand Down

0 comments on commit 32953fd

Please sign in to comment.