mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Correct gogogate2 battery sensor attributes (#47302)
This commit is contained in:
parent
8f3c2573e2
commit
b147ba1377
@ -122,8 +122,6 @@ class DeviceCover(GoGoGate2Entity, CoverEntity):
|
||||
await self._api.async_close_door(self._get_door().door_id)
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attrs = super().state_attributes
|
||||
attrs["door_id"] = self._get_door().door_id
|
||||
return attrs
|
||||
return {"door_id": self._get_door().door_id}
|
||||
|
@ -50,10 +50,9 @@ class DoorSensor(GoGoGate2Entity):
|
||||
return door.voltage # This is a percentage, not an absolute voltage
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attrs = super().state_attributes or {}
|
||||
door = self._get_door()
|
||||
if door.sensorid is not None:
|
||||
attrs["sensorid"] = door.door_id
|
||||
return attrs
|
||||
return {"door_id": door.door_id, "sensor_id": door.sensorid}
|
||||
return None
|
||||
|
@ -21,6 +21,8 @@ from homeassistant.components.cover import (
|
||||
DEVICE_CLASS_GARAGE,
|
||||
DEVICE_CLASS_GATE,
|
||||
DOMAIN as COVER_DOMAIN,
|
||||
SUPPORT_CLOSE,
|
||||
SUPPORT_OPEN,
|
||||
)
|
||||
from homeassistant.components.gogogate2.const import (
|
||||
DEVICE_TYPE_GOGOGATE2,
|
||||
@ -319,6 +321,13 @@ async def test_open_close_update(gogogate2api_mock, hass: HomeAssistant) -> None
|
||||
wifi=Wifi(SSID="", linkquality="", signal=""),
|
||||
)
|
||||
|
||||
expected_attributes = {
|
||||
"device_class": "garage",
|
||||
"door_id": 1,
|
||||
"friendly_name": "Door1",
|
||||
"supported_features": SUPPORT_CLOSE | SUPPORT_OPEN,
|
||||
}
|
||||
|
||||
api = MagicMock(GogoGate2Api)
|
||||
api.async_activate.return_value = GogoGate2ActivateResponse(result=True)
|
||||
api.async_info.return_value = info_response(DoorStatus.OPENED)
|
||||
@ -339,6 +348,7 @@ async def test_open_close_update(gogogate2api_mock, hass: HomeAssistant) -> None
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("cover.door1").state == STATE_OPEN
|
||||
assert dict(hass.states.get("cover.door1").attributes) == expected_attributes
|
||||
|
||||
api.async_info.return_value = info_response(DoorStatus.CLOSED)
|
||||
await hass.services.async_call(
|
||||
@ -376,6 +386,13 @@ async def test_availability(ismartgateapi_mock, hass: HomeAssistant) -> None:
|
||||
"""Test availability."""
|
||||
closed_door_response = _mocked_ismartgate_closed_door_response()
|
||||
|
||||
expected_attributes = {
|
||||
"device_class": "garage",
|
||||
"door_id": 1,
|
||||
"friendly_name": "Door1",
|
||||
"supported_features": SUPPORT_CLOSE | SUPPORT_OPEN,
|
||||
}
|
||||
|
||||
api = MagicMock(ISmartGateApi)
|
||||
api.async_info.return_value = closed_door_response
|
||||
ismartgateapi_mock.return_value = api
|
||||
@ -416,6 +433,7 @@ async def test_availability(ismartgateapi_mock, hass: HomeAssistant) -> None:
|
||||
async_fire_time_changed(hass, utcnow() + timedelta(hours=2))
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("cover.door1").state == STATE_CLOSED
|
||||
assert dict(hass.states.get("cover.door1").attributes) == expected_attributes
|
||||
|
||||
|
||||
@patch("homeassistant.components.gogogate2.common.ISmartGateApi")
|
||||
|
@ -164,6 +164,13 @@ def _mocked_ismartgate_sensor_response(battery_level: int):
|
||||
async def test_sensor_update(gogogate2api_mock, hass: HomeAssistant) -> None:
|
||||
"""Test data update."""
|
||||
|
||||
expected_attributes = {
|
||||
"device_class": "battery",
|
||||
"door_id": 1,
|
||||
"friendly_name": "Door1 battery",
|
||||
"sensor_id": "ABCD",
|
||||
}
|
||||
|
||||
api = MagicMock(GogoGate2Api)
|
||||
api.async_activate.return_value = GogoGate2ActivateResponse(result=True)
|
||||
api.async_info.return_value = _mocked_gogogate_sensor_response(25)
|
||||
@ -192,6 +199,9 @@ async def test_sensor_update(gogogate2api_mock, hass: HomeAssistant) -> None:
|
||||
assert hass.states.get("cover.door2")
|
||||
assert hass.states.get("cover.door2")
|
||||
assert hass.states.get("sensor.door1_battery").state == "25"
|
||||
assert (
|
||||
dict(hass.states.get("sensor.door1_battery").attributes) == expected_attributes
|
||||
)
|
||||
assert hass.states.get("sensor.door2_battery") is None
|
||||
assert hass.states.get("sensor.door2_battery") is None
|
||||
|
||||
@ -212,6 +222,13 @@ async def test_sensor_update(gogogate2api_mock, hass: HomeAssistant) -> None:
|
||||
@patch("homeassistant.components.gogogate2.common.ISmartGateApi")
|
||||
async def test_availability(ismartgateapi_mock, hass: HomeAssistant) -> None:
|
||||
"""Test availability."""
|
||||
expected_attributes = {
|
||||
"device_class": "battery",
|
||||
"door_id": 1,
|
||||
"friendly_name": "Door1 battery",
|
||||
"sensor_id": "ABCD",
|
||||
}
|
||||
|
||||
sensor_response = _mocked_ismartgate_sensor_response(35)
|
||||
api = MagicMock(ISmartGateApi)
|
||||
api.async_info.return_value = sensor_response
|
||||
@ -259,3 +276,6 @@ async def test_availability(ismartgateapi_mock, hass: HomeAssistant) -> None:
|
||||
async_fire_time_changed(hass, utcnow() + timedelta(hours=2))
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("sensor.door1_battery").state == "35"
|
||||
assert (
|
||||
dict(hass.states.get("sensor.door1_battery").attributes) == expected_attributes
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user