Skip to content

Commit

Permalink
Now that's an improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
jzucker2 committed Sep 25, 2024
1 parent 452b565 commit 79c227f
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions tests/components/prometheus/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class MetricInfo:
object_id: str
metric_value: Any | None = None
mode: str | None = None
state: str | None = None

@property
def entity(self):
Expand All @@ -111,12 +112,14 @@ def get_full_metric_string(self):
f" {self.metric_value}" if self.metric_value is not None else ""
)
final_mode_value = f',mode="{self.mode}"' if self.mode is not None else ""
final_state_value = f',state="{self.state}"' if self.state is not None else ""
return (
f"{self.metric_name}{{"
f'domain="{self.domain}",'
f'entity="{self.entity}",'
f'friendly_name="{self.friendly_name}"'
f"{final_mode_value}"
f"{final_state_value}"
f"}}{final_metric_value}"
)

Expand Down Expand Up @@ -152,7 +155,7 @@ def test_metric_info_generates_entity() -> None:


def test_metric_info_generates_metric_string_with_value() -> None:
"""Test using MetricInfo to format a simple metric string but with a value included."""
"""Test using MetricInfo to format a simple metric string but with a metric value included."""
metric_info = MetricInfo(
metric_name="homeassistant_sensor_temperature_celsius",
domain="sensor",
Expand All @@ -170,7 +173,7 @@ def test_metric_info_generates_metric_string_with_value() -> None:


def test_metric_info_generates_metric_string_with_mode_value() -> None:
"""Test using MetricInfo to format a simple metric string but with a value included."""
"""Test using MetricInfo to format a simple metric string but with a mode value included."""
metric_info = MetricInfo(
metric_name="climate_preset_mode",
domain="climate",
Expand All @@ -190,6 +193,27 @@ def test_metric_info_generates_metric_string_with_mode_value() -> None:
)


def test_metric_info_generates_metric_string_with_state_value() -> None:
"""Test using MetricInfo to format a simple metric string but with a state value included."""
metric_info = MetricInfo(
metric_name="cover_state",
domain="cover",
friendly_name="Curtain",
object_id="curtain",
metric_value="1.0",
state="open",
)
assert metric_info.get_full_metric_string() == (
"cover_state{"
'domain="cover",'
'entity="cover.curtain",'
'friendly_name="Curtain",'
'state="open"'
"}"
" 1.0"
)


@pytest.fixture(name="client")
async def setup_prometheus_client(
hass: HomeAssistant,
Expand Down

0 comments on commit 79c227f

Please sign in to comment.