forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sensor tests to Streamlabs water (home-assistant#107065)
- Loading branch information
Showing
7 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
"""Tests for the StreamLabs integration.""" | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM | ||
|
||
from tests.common import MockConfigEntry | ||
|
||
|
||
async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry) -> None: | ||
"""Fixture for setting up the component.""" | ||
config_entry.add_to_hass(hass) | ||
|
||
hass.config.units = IMPERIAL_SYSTEM | ||
|
||
await hass.config_entries.async_setup(config_entry.entry_id) | ||
await hass.async_block_till_done() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tests/components/streamlabswater/fixtures/get_locations.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"pageCount": 1, | ||
"perPage": 50, | ||
"page": 1, | ||
"total": 1, | ||
"locations": [ | ||
{ | ||
"locationId": "945e7c52-854a-41e1-8524-50c6993277e1", | ||
"name": "Water Monitor", | ||
"homeAway": "home", | ||
"devices": [ | ||
{ | ||
"deviceId": "09bec87a-fff2-4b8a-bc00-86d5928f19f3", | ||
"type": "monitor", | ||
"calibrated": true, | ||
"connected": true | ||
} | ||
], | ||
"alerts": [], | ||
"subscriptionIds": [], | ||
"active": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"thisYear": 65432.389256934, | ||
"today": 200.44691536, | ||
"units": "gallons", | ||
"thisMonth": 420.514099294 | ||
} |
136 changes: 136 additions & 0 deletions
136
tests/components/streamlabswater/snapshots/test_sensor.ambr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# serializer version: 1 | ||
# name: test_all_entities[sensor.water_monitor_daily_water-entry] | ||
EntityRegistryEntrySnapshot({ | ||
'aliases': set({ | ||
}), | ||
'area_id': None, | ||
'capabilities': None, | ||
'config_entry_id': <ANY>, | ||
'device_class': None, | ||
'device_id': <ANY>, | ||
'disabled_by': None, | ||
'domain': 'sensor', | ||
'entity_category': None, | ||
'entity_id': 'sensor.water_monitor_daily_water', | ||
'has_entity_name': False, | ||
'hidden_by': None, | ||
'icon': None, | ||
'id': <ANY>, | ||
'name': None, | ||
'options': dict({ | ||
}), | ||
'original_device_class': <SensorDeviceClass.WATER: 'water'>, | ||
'original_icon': None, | ||
'original_name': 'Water Monitor Daily Water', | ||
'platform': 'streamlabswater', | ||
'previous_unique_id': None, | ||
'supported_features': 0, | ||
'translation_key': None, | ||
'unique_id': '945e7c52-854a-41e1-8524-50c6993277e1-daily_usage', | ||
'unit_of_measurement': <UnitOfVolume.GALLONS: 'gal'>, | ||
}) | ||
# --- | ||
# name: test_all_entities[sensor.water_monitor_daily_water-state] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'device_class': 'water', | ||
'friendly_name': 'Water Monitor Daily Water', | ||
'unit_of_measurement': <UnitOfVolume.GALLONS: 'gal'>, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'sensor.water_monitor_daily_water', | ||
'last_changed': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '200.4', | ||
}) | ||
# --- | ||
# name: test_all_entities[sensor.water_monitor_monthly_water-entry] | ||
EntityRegistryEntrySnapshot({ | ||
'aliases': set({ | ||
}), | ||
'area_id': None, | ||
'capabilities': None, | ||
'config_entry_id': <ANY>, | ||
'device_class': None, | ||
'device_id': <ANY>, | ||
'disabled_by': None, | ||
'domain': 'sensor', | ||
'entity_category': None, | ||
'entity_id': 'sensor.water_monitor_monthly_water', | ||
'has_entity_name': False, | ||
'hidden_by': None, | ||
'icon': None, | ||
'id': <ANY>, | ||
'name': None, | ||
'options': dict({ | ||
}), | ||
'original_device_class': <SensorDeviceClass.WATER: 'water'>, | ||
'original_icon': None, | ||
'original_name': 'Water Monitor Monthly Water', | ||
'platform': 'streamlabswater', | ||
'previous_unique_id': None, | ||
'supported_features': 0, | ||
'translation_key': None, | ||
'unique_id': '945e7c52-854a-41e1-8524-50c6993277e1-monthly_usage', | ||
'unit_of_measurement': <UnitOfVolume.GALLONS: 'gal'>, | ||
}) | ||
# --- | ||
# name: test_all_entities[sensor.water_monitor_monthly_water-state] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'device_class': 'water', | ||
'friendly_name': 'Water Monitor Monthly Water', | ||
'unit_of_measurement': <UnitOfVolume.GALLONS: 'gal'>, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'sensor.water_monitor_monthly_water', | ||
'last_changed': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '420.5', | ||
}) | ||
# --- | ||
# name: test_all_entities[sensor.water_monitor_yearly_water-entry] | ||
EntityRegistryEntrySnapshot({ | ||
'aliases': set({ | ||
}), | ||
'area_id': None, | ||
'capabilities': None, | ||
'config_entry_id': <ANY>, | ||
'device_class': None, | ||
'device_id': <ANY>, | ||
'disabled_by': None, | ||
'domain': 'sensor', | ||
'entity_category': None, | ||
'entity_id': 'sensor.water_monitor_yearly_water', | ||
'has_entity_name': False, | ||
'hidden_by': None, | ||
'icon': None, | ||
'id': <ANY>, | ||
'name': None, | ||
'options': dict({ | ||
}), | ||
'original_device_class': <SensorDeviceClass.WATER: 'water'>, | ||
'original_icon': None, | ||
'original_name': 'Water Monitor Yearly Water', | ||
'platform': 'streamlabswater', | ||
'previous_unique_id': None, | ||
'supported_features': 0, | ||
'translation_key': None, | ||
'unique_id': '945e7c52-854a-41e1-8524-50c6993277e1-yearly_usage', | ||
'unit_of_measurement': <UnitOfVolume.GALLONS: 'gal'>, | ||
}) | ||
# --- | ||
# name: test_all_entities[sensor.water_monitor_yearly_water-state] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'device_class': 'water', | ||
'friendly_name': 'Water Monitor Yearly Water', | ||
'unit_of_measurement': <UnitOfVolume.GALLONS: 'gal'>, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'sensor.water_monitor_yearly_water', | ||
'last_changed': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '65432.4', | ||
}) | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Tests for the Streamlabs Water sensor platform.""" | ||
from unittest.mock import AsyncMock, patch | ||
|
||
from syrupy import SnapshotAssertion | ||
|
||
from homeassistant.const import Platform | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import entity_registry as er | ||
|
||
from tests.common import MockConfigEntry | ||
from tests.components.streamlabswater import setup_integration | ||
|
||
|
||
async def test_all_entities( | ||
hass: HomeAssistant, | ||
snapshot: SnapshotAssertion, | ||
streamlabswater: AsyncMock, | ||
mock_config_entry: MockConfigEntry, | ||
entity_registry: er.EntityRegistry, | ||
) -> None: | ||
"""Test all entities.""" | ||
with patch("homeassistant.components.streamlabswater.PLATFORMS", [Platform.SENSOR]): | ||
await setup_integration(hass, mock_config_entry) | ||
entity_entries = er.async_entries_for_config_entry( | ||
entity_registry, mock_config_entry.entry_id | ||
) | ||
|
||
assert entity_entries | ||
for entity_entry in entity_entries: | ||
assert entity_entry == snapshot(name=f"{entity_entry.entity_id}-entry") | ||
assert hass.states.get(entity_entry.entity_id) == snapshot( | ||
name=f"{entity_entry.entity_id}-state" | ||
) |