|
6 | 6 | import pytest |
7 | 7 | from syrupy.assertion import SnapshotAssertion |
8 | 8 |
|
| 9 | +from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN |
9 | 10 | from homeassistant.components.smlight.const import DOMAIN |
10 | 11 | from homeassistant.const import STATE_UNKNOWN, Platform |
11 | 12 | from homeassistant.core import HomeAssistant |
@@ -113,3 +114,55 @@ async def test_zigbee_type_sensors( |
113 | 114 | state = hass.states.get("sensor.mock_title_zigbee_type_2") |
114 | 115 | assert state |
115 | 116 | assert state.state == "router" |
| 117 | + |
| 118 | + |
| 119 | +@pytest.mark.usefixtures("entity_registry_enabled_by_default") |
| 120 | +async def test_psram_usage_sensor( |
| 121 | + hass: HomeAssistant, |
| 122 | + mock_config_entry: MockConfigEntry, |
| 123 | + mock_smlight_client: MagicMock, |
| 124 | + entity_registry: er.EntityRegistry, |
| 125 | +) -> None: |
| 126 | + """Test PSRAM usage sensor creation for u-devices.""" |
| 127 | + mock_smlight_client.get_info.side_effect = None |
| 128 | + mock_smlight_client.get_info.return_value = Info( |
| 129 | + MAC="AA:BB:CC:DD:EE:FF", |
| 130 | + model="SLZB-MR3U", |
| 131 | + u_device=True, |
| 132 | + ) |
| 133 | + mock_smlight_client.get_sensors.return_value = Sensors(psram_usage=156) |
| 134 | + |
| 135 | + await setup_integration(hass, mock_config_entry) |
| 136 | + |
| 137 | + entity_id = entity_registry.async_get_entity_id( |
| 138 | + SENSOR_DOMAIN, DOMAIN, "aa:bb:cc:dd:ee:ff_psram_usage" |
| 139 | + ) |
| 140 | + assert entity_id is not None |
| 141 | + |
| 142 | + state = hass.states.get(entity_id) |
| 143 | + assert state is not None |
| 144 | + assert state.state == "156" |
| 145 | + assert state.attributes["unit_of_measurement"] == "kB" |
| 146 | + |
| 147 | + |
| 148 | +async def test_psram_usage_sensor_not_created( |
| 149 | + hass: HomeAssistant, |
| 150 | + mock_config_entry: MockConfigEntry, |
| 151 | + mock_smlight_client: MagicMock, |
| 152 | + entity_registry: er.EntityRegistry, |
| 153 | +) -> None: |
| 154 | + """Test PSRAM usage sensor is not created for non-u devices.""" |
| 155 | + mock_smlight_client.get_info.side_effect = None |
| 156 | + mock_smlight_client.get_info.return_value = Info( |
| 157 | + MAC="AA:BB:CC:DD:EE:FF", |
| 158 | + model="SLZB-MR3", |
| 159 | + u_device=False, |
| 160 | + ) |
| 161 | + await setup_integration(hass, mock_config_entry) |
| 162 | + |
| 163 | + assert hass.states.get("sensor.mock_title_psram_usage") is None |
| 164 | + |
| 165 | + entity_id = entity_registry.async_get_entity_id( |
| 166 | + SENSOR_DOMAIN, DOMAIN, "aa:bb:cc:dd:ee:ff_psram_usage" |
| 167 | + ) |
| 168 | + assert entity_id is None |
0 commit comments