mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Fix Datadog boolean metrics (#37273)
Explicitly cast boolean metrics to integers
This commit is contained in:
parent
992793295c
commit
b56f4bd9f8
@ -82,6 +82,7 @@ def setup(hass, config):
|
||||
for key, value in states.items():
|
||||
if isinstance(value, (float, int)):
|
||||
attribute = f"{metric}.{key.replace(' ', '_')}"
|
||||
value = int(value) if isinstance(value, bool) else value
|
||||
statsd.gauge(attribute, value, sample_rate=sample_rate, tags=tags)
|
||||
|
||||
_LOGGER.debug("Sent metric %s: %s (tags: %s)", attribute, value, tags)
|
||||
|
@ -134,7 +134,7 @@ class TestDatadog(unittest.TestCase):
|
||||
|
||||
valid = {"1": 1, "1.0": 1.0, STATE_ON: 1, STATE_OFF: 0}
|
||||
|
||||
attributes = {"elevation": 3.2, "temperature": 5.0}
|
||||
attributes = {"elevation": 3.2, "temperature": 5.0, "up": True, "down": False}
|
||||
|
||||
for in_, out in valid.items():
|
||||
state = mock.MagicMock(
|
||||
@ -145,9 +145,10 @@ class TestDatadog(unittest.TestCase):
|
||||
)
|
||||
handler_method(mock.MagicMock(data={"new_state": state}))
|
||||
|
||||
assert mock_client.gauge.call_count == 3
|
||||
assert mock_client.gauge.call_count == 5
|
||||
|
||||
for attribute, value in attributes.items():
|
||||
value = int(value) if isinstance(value, bool) else value
|
||||
mock_client.gauge.assert_has_calls(
|
||||
[
|
||||
mock.call(
|
||||
|
Loading…
x
Reference in New Issue
Block a user