Skip to content

Commit 4506f5a

Browse files
committed
Limit current folder sensor attributes
1 parent d65a139 commit 4506f5a

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

custom_components/sharepoint_photos/sensor.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,28 +164,41 @@ def extra_state_attributes(self) -> Dict[str, Any]:
164164
photo_urls = [url for url in photo_urls if url]
165165

166166
# Calculate rotating picture URL (changes every 10 seconds)
167-
current_picture_url = ""
167+
current_picture_url = None
168+
current_photo = None
169+
preview_urls: List[str] = []
170+
168171
if photo_urls:
169172
# Use current time to create a rotating index that changes every 10 seconds
170173
import time
174+
171175
cycle_time = 10 # seconds
172176
current_cycle = int(time.time() / cycle_time)
173177
picture_index = current_cycle % len(photo_urls)
174178
current_picture_url = photo_urls[picture_index]
175-
176-
current_photo = None
177-
if photos and photo_urls:
178-
current_photo = photos[picture_index]
179+
if photos and picture_index < len(photos):
180+
current_photo = photos[picture_index]
179181

180-
return {
181-
"photos": photos,
182-
"photo_urls": photo_urls,
183-
"current_picture_url": current_picture_url,
184-
"current_picture_label": current_photo.get("name") if current_photo else None,
182+
preview_urls = photo_urls[:5] # keep attributes compact for recorder
183+
184+
attributes: Dict[str, Any] = {
185185
"folder_path": data.get("folder_path"),
186186
"photo_count": len(photos),
187187
"rotation_cycle_seconds": 10,
188+
"current_picture_url": current_picture_url,
189+
"current_picture_label": current_photo.get("name") if current_photo else None,
188190
}
191+
192+
if preview_urls:
193+
attributes["preview_urls"] = preview_urls
194+
195+
if current_photo:
196+
attributes["current_photo_id"] = current_photo.get("id")
197+
attributes["current_photo_name"] = current_photo.get("name")
198+
if current_photo.get("web_url"):
199+
attributes["current_photo_web_url"] = current_photo["web_url"]
200+
201+
return attributes
189202

190203
return {}
191204

0 commit comments

Comments
 (0)