Skip to content
3 changes: 3 additions & 0 deletions homeassistant/components/blebox/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
key="moisture",
device_class=BinarySensorDeviceClass.MOISTURE,
),
BinarySensorEntityDescription(
key="input",
),
Comment thread
bkobus-bbx marked this conversation as resolved.
Comment thread
bkobus-bbx marked this conversation as resolved.
)


Expand Down
70 changes: 61 additions & 9 deletions tests/components/blebox/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,72 @@ def airsensor_fixture() -> tuple[AsyncMock, str]:
return feature, "binary_sensor.my_rain_sensor_windrainsensor_0_rain"


@pytest.fixture(name="inputsensor")
def inputsensor_fixture() -> tuple[AsyncMock, str]:
"""Return a default inputSensor fixture."""
feature: AsyncMock = mock_feature(
"binary_sensors",
blebox_uniapi.binary_sensor.Input,
unique_id="BleBox-inputSensorD-aa11bb22cc33-0.input",
full_name="inputSensorD-0.input",
device_class="input",
Comment thread
bkobus-bbx marked this conversation as resolved.
)
Comment thread
bkobus-bbx marked this conversation as resolved.
product = feature.product
type(product).name = PropertyMock(return_value="My input sensor")
type(product).model = PropertyMock(return_value="inputSensorD")
Comment thread
bkobus-bbx marked this conversation as resolved.
return feature, "binary_sensor.my_input_sensor_inputsensord_0_input"


@pytest.mark.parametrize(
(
"fixture_name",
"entity_id",
"unique_id",
"expected_name",
"expected_device_class",
"expected_state",
),
[
pytest.param(
"rainsensor",
"binary_sensor.my_rain_sensor_windrainsensor_0_rain",
"BleBox-windRainSensor-ea68e74f4f49-0.rain",
"My rain sensor windRainSensor-0.rain",
BinarySensorDeviceClass.MOISTURE,
STATE_ON,
id="moisture",
),
pytest.param(
"inputsensor",
"binary_sensor.my_input_sensor_inputsensord_0_input",
"BleBox-inputSensorD-aa11bb22cc33-0.input",
"My input sensor inputSensorD-0.input",
None,
STATE_ON,
id="input",
),
],
)
async def test_init(
rainsensor: AsyncMock, device_registry: dr.DeviceRegistry, hass: HomeAssistant
fixture_name: str,
entity_id: str,
unique_id: str,
expected_name: str,
expected_device_class: BinarySensorDeviceClass | None,
expected_state: str,
device_registry: dr.DeviceRegistry,
hass: HomeAssistant,
Comment thread
bkobus-bbx marked this conversation as resolved.
Outdated
request: pytest.FixtureRequest,
) -> None:
"""Test binary_sensor initialisation."""
_, entity_id = rainsensor
request.getfixturevalue(fixture_name)
entry = await async_setup_entity(hass, entity_id)
Comment thread
bkobus-bbx marked this conversation as resolved.
Outdated
assert entry.unique_id == "BleBox-windRainSensor-ea68e74f4f49-0.rain"
assert entry.unique_id == unique_id

state = hass.states.get(entity_id)
assert state.name == "My rain sensor windRainSensor-0.rain"

assert state.attributes[ATTR_DEVICE_CLASS] == BinarySensorDeviceClass.MOISTURE
assert state.state == STATE_ON
assert state.name == expected_name
assert state.attributes.get(ATTR_DEVICE_CLASS) == expected_device_class
assert state.state == expected_state

device = device_registry.async_get(entry.device_id)

assert device.name == "My rain sensor"
assert device is not None
Comment thread
bkobus-bbx marked this conversation as resolved.
Outdated