@@ -37,8 +37,8 @@ def test_battery_sensor_unique_id(coord_with_locks):
3737
3838
3939async def test_async_setup_entry_adds_one_per_lock (hass , coord_with_locks ):
40- """Initial setup should add battery sensors for all locks."""
41- from custom_components .u_tec .sensor import async_setup_entry
40+ """Initial setup should add battery sensors for all locks plus one last-push sensor ."""
41+ from custom_components .u_tec .sensor import UhomeBatterySensorEntity , async_setup_entry
4242
4343 coord , entry = coord_with_locks
4444 hass .data .setdefault (DOMAIN , {})[entry .entry_id ] = {"coordinator" : coord }
@@ -48,7 +48,9 @@ def _add(entities):
4848 added .extend (list (entities ))
4949
5050 await async_setup_entry (hass , entry , _add )
51- assert len (added ) == 2
51+ battery_sensors = [e for e in added if isinstance (e , UhomeBatterySensorEntity )]
52+ assert len (battery_sensors ) == 2
53+ assert len (added ) == 3 # 2 battery + 1 last-push
5254 assert coord .added_sensor_entities == {"u_tec_battery_lock-1" , "u_tec_battery_lock-2" }
5355
5456
@@ -97,3 +99,34 @@ def _add(entities):
9799
98100 # Same devices -> no additions
99101 assert len (added ) == initial
102+
103+
104+ async def test_last_push_sensor_added_once (hass , coord_with_locks ):
105+ """async_setup_entry adds exactly one coordinator-level last-push sensor."""
106+ from custom_components .u_tec .sensor import UhomeLastPushSensor , async_setup_entry
107+
108+ coord , entry = coord_with_locks
109+ hass .data .setdefault (DOMAIN , {})[entry .entry_id ] = {"coordinator" : coord }
110+ added = []
111+ await async_setup_entry (hass , entry , lambda ents : added .extend (list (ents )))
112+
113+ last_push = [e for e in added if isinstance (e , UhomeLastPushSensor )]
114+ assert len (last_push ) == 1
115+
116+
117+ async def test_last_push_sensor_native_value_and_class (hass , coord_with_locks ):
118+ """The sensor reports the coordinator's last_push_received as a timestamp."""
119+ from homeassistant .components .sensor import SensorDeviceClass
120+ from homeassistant .util import dt as dt_util
121+
122+ from custom_components .u_tec .sensor import UhomeLastPushSensor
123+
124+ coord , _ = coord_with_locks
125+ coord .last_push_received = None
126+ sensor = UhomeLastPushSensor (coord )
127+ assert sensor .device_class == SensorDeviceClass .TIMESTAMP
128+
129+ assert sensor .native_value is None # no push yet
130+ stamp = dt_util .utcnow ()
131+ coord .last_push_received = stamp
132+ assert sensor .native_value == stamp
0 commit comments