8000 Fixed statsd stopping if state is not numeric or only attributes changed by brentahughes · Pull Request #3981 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixed statsd stopping if state is not numeric or only attributes changed #3981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions homeassistant/components/statsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,20 @@ def statsd_event_listener(event):
try:
_state = state_helper.state_as_number(state)
except ValueError:
return
# Set the state to none and continue for any numeric attributes.
_state = None

states = dict(state.attributes)

_LOGGER.debug('Sending %s.%s', state.entity_id, _state)
_LOGGER.debug('Sending %s', state.entity_id)

if show_attribute_flag is True:
statsd_client.gauge(
"%s.state" % state.entity_id,
_state,
sample_rate
)
if isinstance(_state, (float, int)):
statsd_client.gauge(
"%s.state" % state.entity_id,
_state,
sample_rate
)

# Send attribute values
for key, value in states.items():
Expand All @@ -81,7 +83,8 @@ def statsd_event_listener(event):
statsd_client.gauge(stat, value, sample_rate)

else:
statsd_client.gauge(state.entity_id, _state, sample_rate)
if is 8000 instance(_state, (float, int)):
statsd_client.gauge(state.entity_id, _state, sample_rate)

# Increment the count
statsd_client.incr(state.entity_id, rate=sample_rate)
Expand Down
4 changes: 2 additions & 2 deletions tests/components/test_statsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_event_listener_defaults(self, mock_client):
handler_method(mock.MagicMock(data={
'new_state': ha.State('domain.test', invalid, {})}))
self.assertFalse(mock_client.return_value.gauge.called)
self.assertFalse(mock_client.return_value.incr.called)
self.assertTrue(mock_client.return_value.incr.called)

@mock.patch('statsd.StatsClient')
def test_event_listener_attr_details(self, mock_client):
Expand Down Expand Up @@ -162,4 +162,4 @@ def test_event_listener_attr_details(self, mock_client):
handler_method(mock.MagicMock(data={
'new_state': ha.State('domain.test', invalid, {})}))
self.assertFalse(mock_client.return_value.gauge.called)
self.assertFalse(mock_client.return_value.incr.called)
self.assertTrue(mock_client.return_value.incr.called)
0