From b56f4bd9f898694e65e4257931a9f0b625e9efe3 Mon Sep 17 00:00:00 2001 From: Rick Sherman <rick@shermdog.com> Date: Sun, 5 Jul 2020 12:50:51 -0500 Subject: [PATCH] Fix Datadog boolean metrics (#37273) Explicitly cast boolean metrics to integers --- homeassistant/components/datadog/__init__.py | 1 + tests/components/datadog/test_init.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/datadog/__init__.py b/homeassistant/components/datadog/__init__.py index b5b7664f8b0..5d3aae3de20 100644 --- a/homeassistant/components/datadog/__init__.py +++ b/homeassistant/components/datadog/__init__.py @@ -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) diff --git a/tests/components/datadog/test_init.py b/tests/components/datadog/test_init.py index 9ba64bb43ff..da4076944d0 100644 --- a/tests/components/datadog/test_init.py +++ b/tests/components/datadog/test_init.py @@ -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( -- GitLab