-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update number platform values before add in APSystems and add tests (#…
…131938) Co-authored-by: epenet <[email protected]>
- Loading branch information
1 parent
352e948
commit 51bead3
Showing
4 changed files
with
121 additions
and
1 deletion.
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
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,58 @@ | ||
# serializer version: 1 | ||
# name: test_all_entities[number.mock_title_max_output-entry] | ||
EntityRegistryEntrySnapshot({ | ||
'aliases': set({ | ||
}), | ||
'area_id': None, | ||
'capabilities': dict({ | ||
'max': 1000, | ||
'min': 0, | ||
'mode': <NumberMode.BOX: 'box'>, | ||
'step': 1, | ||
}), | ||
'config_entry_id': <ANY>, | ||
'device_class': None, | ||
'device_id': <ANY>, | ||
'disabled_by': None, | ||
'domain': 'number', | ||
'entity_category': None, | ||
'entity_id': 'number.mock_title_max_output', | ||
'has_entity_name': True, | ||
'hidden_by': None, | ||
'icon': None, | ||
'id': <ANY>, | ||
'labels': set({ | ||
}), | ||
'name': None, | ||
'options': dict({ | ||
}), | ||
'original_device_class': <NumberDeviceClass.POWER: 'power'>, | ||
'original_icon': None, | ||
'original_name': 'Max output', | ||
'platform': 'apsystems', | ||
'previous_unique_id': None, | ||
'supported_features': 0, | ||
'translation_key': 'max_output', | ||
'unique_id': 'MY_SERIAL_NUMBER_output_limit', | ||
'unit_of_measurement': <UnitOfPower.WATT: 'W'>, | ||
}) | ||
# --- | ||
# name: test_all_entities[number.mock_title_max_output-state] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'device_class': 'power', | ||
'friendly_name': 'Mock Title Max output', | ||
'max': 1000, | ||
'min': 0, | ||
'mode': <NumberMode.BOX: 'box'>, | ||
'step': 1, | ||
'unit_of_measurement': <UnitOfPower.WATT: 'W'>, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'number.mock_title_max_output', | ||
'last_changed': <ANY>, | ||
'last_reported': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '666', | ||
}) | ||
# --- |
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,61 @@ | ||
"""Test the APSystem number module.""" | ||
|
||
import datetime | ||
from unittest.mock import AsyncMock, patch | ||
|
||
from freezegun.api import FrozenDateTimeFactory | ||
import pytest | ||
from syrupy import SnapshotAssertion | ||
|
||
from homeassistant.components.number import ( | ||
ATTR_VALUE, | ||
DOMAIN as NUMBER_DOMAIN, | ||
SERVICE_SET_VALUE, | ||
) | ||
from homeassistant.const import ATTR_ENTITY_ID, Platform | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import entity_registry as er | ||
|
||
from . import setup_integration | ||
|
||
from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform | ||
|
||
SCAN_INTERVAL = datetime.timedelta(seconds=30) | ||
|
||
|
||
async def test_number( | ||
hass: HomeAssistant, | ||
mock_apsystems: AsyncMock, | ||
mock_config_entry: MockConfigEntry, | ||
freezer: FrozenDateTimeFactory, | ||
) -> None: | ||
"""Test number command.""" | ||
await setup_integration(hass, mock_config_entry) | ||
entity_id = "number.mock_title_max_output" | ||
await hass.services.async_call( | ||
NUMBER_DOMAIN, | ||
SERVICE_SET_VALUE, | ||
service_data={ATTR_VALUE: 50.1}, | ||
target={ATTR_ENTITY_ID: entity_id}, | ||
blocking=True, | ||
) | ||
mock_apsystems.set_max_power.assert_called_once_with(50) | ||
mock_apsystems.get_max_power.return_value = 50 | ||
freezer.tick(SCAN_INTERVAL) | ||
async_fire_time_changed(hass) | ||
await hass.async_block_till_done() | ||
state = hass.states.get(entity_id) | ||
assert state.state == "50" | ||
|
||
|
||
@pytest.mark.usefixtures("mock_apsystems") | ||
@patch("homeassistant.components.apsystems.PLATFORMS", [Platform.NUMBER]) | ||
async def test_all_entities( | ||
hass: HomeAssistant, | ||
snapshot: SnapshotAssertion, | ||
mock_config_entry: MockConfigEntry, | ||
entity_registry: er.EntityRegistry, | ||
) -> None: | ||
"""Test all entities.""" | ||
await setup_integration(hass, mock_config_entry) | ||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) |