feat(ha): add expiring_today, next_expiry_name/date, expires_today flag
This commit is contained in:
+11
-1
@@ -1409,6 +1409,12 @@ function haInventorySensor(PDO $db): void {
|
||||
AND expiry_date BETWEEN date('now') AND date('now', '+3 days')"
|
||||
)->fetchColumn();
|
||||
|
||||
// Items expiring today or tomorrow (max urgency)
|
||||
$expiringToday = (int)$db->query(
|
||||
"SELECT COUNT(*) FROM inventory WHERE quantity > 0 AND expiry_date IS NOT NULL
|
||||
AND expiry_date <= date('now', '+1 days')"
|
||||
)->fetchColumn();
|
||||
|
||||
// Shopping total from server-side total cache (max 1 hour old)
|
||||
$priceEnabled = env('PRICE_ENABLED', 'false') === 'true';
|
||||
$priceCurrency = env('PRICE_CURRENCY', 'EUR');
|
||||
@@ -1444,6 +1450,7 @@ function haInventorySensor(PDO $db): void {
|
||||
'attributes' => [
|
||||
'expiring_soon' => $expiring,
|
||||
'expiring_3d' => $expiring3d,
|
||||
'expiring_today' => $expiringToday,
|
||||
'expired_items' => $expired,
|
||||
'total_items' => $total,
|
||||
'opened_items' => $openedItems,
|
||||
@@ -1455,8 +1462,11 @@ function haInventorySensor(PDO $db): void {
|
||||
'name' => $r['name'],
|
||||
'quantity' => (float)$r['quantity'],
|
||||
'unit' => $r['unit'],
|
||||
'expiry_date'=> $r['expiry_date'],
|
||||
'expiry_date' => $r['expiry_date'],
|
||||
'expires_today' => $r['expiry_date'] <= date('Y-m-d', strtotime('+1 days')),
|
||||
], $expiringItems),
|
||||
'next_expiry_name' => !empty($expiringItems) ? $expiringItems[0]['name'] : null,
|
||||
'next_expiry_date' => !empty($expiringItems) ? $expiringItems[0]['expiry_date'] : null,
|
||||
'unit_of_measurement' => 'items',
|
||||
'friendly_name' => 'EverShelf Pantry',
|
||||
'icon' => 'mdi:fridge',
|
||||
|
||||
Reference in New Issue
Block a user