Skip to content

Commit af7313f

Browse files
committed
Fix selector translations and mobile performance
1 parent 0831ae9 commit af7313f

File tree

7 files changed

+199
-33
lines changed

7 files changed

+199
-33
lines changed

custom_components/oig_cloud/services.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ def _box_id_from_coordinator() -> Optional[str]:
116116

117117
# Konstanty pro služby
118118
MODES: Dict[str, str] = {
119+
"home_1": "0",
120+
"home_2": "1",
121+
"home_3": "2",
122+
"home_ups": "3",
123+
"home_5": "4",
124+
"home_6": "5",
125+
# Backward-compatible labels (legacy automations)
119126
"Home 1": "0",
120127
"Home 2": "1",
121128
"Home 3": "2",
@@ -124,9 +131,29 @@ def _box_id_from_coordinator() -> Optional[str]:
124131
"Home 6": "5",
125132
}
126133

127-
GRID_DELIVERY = {"Vypnuto / Off": 0, "Zapnuto / On": 1, "S omezením / Limited": 1}
128-
BOILER_MODE = {"CBB": 0, "Manual": 1}
129-
FORMAT_BATTERY = {"Nenabíjet": 0, "Nabíjet": 1}
134+
GRID_DELIVERY = {
135+
"off": 0,
136+
"on": 1,
137+
"limited": 1,
138+
# Backward-compatible labels
139+
"Vypnuto / Off": 0,
140+
"Zapnuto / On": 1,
141+
"S omezením / Limited": 1,
142+
}
143+
BOILER_MODE = {
144+
"cbb": 0,
145+
"manual": 1,
146+
# Backward-compatible labels
147+
"CBB": 0,
148+
"Manual": 1,
149+
}
150+
FORMAT_BATTERY = {
151+
"no_charge": 0,
152+
"charge": 1,
153+
# Backward-compatible labels
154+
"Nenabíjet": 0,
155+
"Nabíjet": 1,
156+
}
130157

131158
tracer = trace.get_tracer(__name__)
132159

custom_components/oig_cloud/services.yaml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ set_box_mode:
1919
description: The mode to set
2020
selector:
2121
select:
22+
translation_key: box_mode
2223
options:
23-
- Home 1
24-
- Home 2
25-
- Home 3
26-
- Home UPS
24+
- home_1
25+
- home_2
26+
- home_3
27+
- home_ups
2728
acknowledgement:
2829
description: |
2930
I acknowledge that calling the service will result in parameter modification of a live system.
@@ -68,10 +69,11 @@ set_grid_delivery:
6869
description: Režim přetoků
6970
selector:
7071
select:
72+
translation_key: grid_delivery_mode
7173
options:
72-
- Vypnuto / Off
73-
- Zapnuto / On
74-
- S omezením / Limited
74+
- off
75+
- on
76+
- limited
7577
limit:
7678
description: Nastavení limitu výkonu přetoků (W)
7779
selector:
@@ -131,9 +133,10 @@ set_boiler_mode:
131133
description: Režim bojleru
132134
selector:
133135
select:
136+
translation_key: boiler_mode
134137
options:
135-
- CBB
136-
- Manual
138+
- cbb
139+
- manual
137140
acknowledgement:
138141
description: |
139142
I acknowledge that calling the service will result in parameter modification of a live system.
@@ -162,9 +165,10 @@ set_formating_mode:
162165
description: Režim nabíjení
163166
selector:
164167
select:
168+
translation_key: battery_charge_mode
165169
options:
166-
- Nenabíjet
167-
- Nabíjet
170+
- no_charge
171+
- charge
168172
limit:
169173
description: Cílové procento nabití
170174
selector:

custom_components/oig_cloud/translations/cs.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,33 @@
650650
"quick": "⚡ Rychlé nastavení",
651651
"wizard": "🧙‍♂️ Průvodce nastavením (doporučeno)"
652652
}
653+
},
654+
"box_mode": {
655+
"options": {
656+
"home_1": "Home 1",
657+
"home_2": "Home 2",
658+
"home_3": "Home 3",
659+
"home_ups": "Home UPS"
660+
}
661+
},
662+
"boiler_mode": {
663+
"options": {
664+
"cbb": "CBB",
665+
"manual": "Manual"
666+
}
667+
},
668+
"battery_charge_mode": {
669+
"options": {
670+
"no_charge": "Nenabíjet",
671+
"charge": "Nabíjet"
672+
}
673+
},
674+
"grid_delivery_mode": {
675+
"options": {
676+
"off": "Vypnuto / Off",
677+
"on": "Zapnuto / On",
678+
"limited": "S omezením / Limited"
679+
}
653680
}
654681
},
655682
"services": {

custom_components/oig_cloud/translations/en.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,33 @@
770770
"quick": "⚡ Quick Setup",
771771
"wizard": "🧙‍♂️ Setup Wizard (recommended)"
772772
}
773+
},
774+
"box_mode": {
775+
"options": {
776+
"home_1": "Home 1",
777+
"home_2": "Home 2",
778+
"home_3": "Home 3",
779+
"home_ups": "Home UPS"
780+
}
781+
},
782+
"boiler_mode": {
783+
"options": {
784+
"cbb": "CBB",
785+
"manual": "Manual"
786+
}
787+
},
788+
"battery_charge_mode": {
789+
"options": {
790+
"no_charge": "Do not charge",
791+
"charge": "Charge"
792+
}
793+
},
794+
"grid_delivery_mode": {
795+
"options": {
796+
"off": "Vypnuto / Off",
797+
"on": "Zapnuto / On",
798+
"limited": "S omezením / Limited"
799+
}
773800
}
774801
},
775802
"services": {

custom_components/oig_cloud/www/js/core/core.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ if (window.OIG_RUNTIME.isHaApp === undefined) {
6060
if (window.OIG_RUNTIME.isMobile === undefined) {
6161
window.OIG_RUNTIME.isMobile = detectMobile();
6262
}
63+
if (window.OIG_RUNTIME.reduceMotion === undefined) {
64+
const prefersReduced = window.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches;
65+
window.OIG_RUNTIME.reduceMotion = !!(prefersReduced || window.OIG_RUNTIME.isHaApp || window.OIG_RUNTIME.isMobile);
66+
}
6367
if (window.OIG_RUNTIME.initialLoadComplete === undefined) {
6468
window.OIG_RUNTIME.initialLoadComplete = false;
6569
}
@@ -336,6 +340,13 @@ var closeGridChargingDialog = window.DashboardGridCharging?.closeGridChargingDia
336340
function init() {
337341
console.log('[Dashboard] Initializing...');
338342
const isConstrainedRuntime = !!(window.OIG_RUNTIME?.isHaApp || window.OIG_RUNTIME?.isMobile);
343+
if (window.OIG_RUNTIME?.reduceMotion) {
344+
document.body.classList.add('oig-reduce-motion');
345+
const particles = document.getElementById('particles');
346+
if (particles) {
347+
particles.style.display = 'none';
348+
}
349+
}
339350

340351
// Detekovat a aplikovat téma z Home Assistantu
341352
detectAndApplyTheme();
@@ -406,8 +417,15 @@ function init() {
406417
}
407418
}, 50);
408419

409-
// Subscribe to shield state changes for real-time updates
410-
subscribeToShield();
420+
// Subscribe to shield state changes for real-time updates (defer on mobile/HA app)
421+
const startShieldSubscription = () => {
422+
subscribeToShield();
423+
};
424+
if (isConstrainedRuntime) {
425+
setTimeout(() => runWhenIdle(startShieldSubscription, 4000, 1500), 300);
426+
} else {
427+
startShieldSubscription();
428+
}
411429

412430
// Initial shield UI update with retry logic (wait for sensors after HA restart)
413431
let retryCount = 0;

custom_components/oig_cloud/www/js/core/state-watcher.js

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,47 @@
3535
function registerPrefix(prefix) {
3636
const hass = _getHassSafe();
3737
if (!hass || !hass.states || typeof prefix !== 'string') return;
38-
const ids = Object.keys(hass.states).filter((eid) => eid.startsWith(prefix));
39-
registerEntities(ids);
38+
39+
const ids = Object.keys(hass.states);
40+
const runtime = window.OIG_RUNTIME || {};
41+
const shouldChunk = !!(runtime.isHaApp || runtime.isMobile || ids.length > 800);
42+
43+
if (!shouldChunk) {
44+
registerEntities(ids.filter((eid) => eid.startsWith(prefix)));
45+
return;
46+
}
47+
48+
let index = 0;
49+
const chunkSize = runtime.isHaApp || runtime.isMobile ? 200 : 400;
50+
51+
const step = (deadline) => {
52+
const timeBudget = deadline && typeof deadline.timeRemaining === 'function'
53+
? deadline.timeRemaining()
54+
: 0;
55+
const useTimeBudget = timeBudget > 0;
56+
const start = index;
57+
while (index < ids.length) {
58+
const id = ids[index];
59+
if (id.startsWith(prefix)) watched.add(id);
60+
index += 1;
61+
if (index - start >= chunkSize) break;
62+
if (useTimeBudget && deadline.timeRemaining() < 3) break;
63+
}
64+
65+
if (index < ids.length) {
66+
schedule();
67+
}
68+
};
69+
70+
const schedule = () => {
71+
if (typeof window.requestIdleCallback === 'function') {
72+
window.requestIdleCallback(step, { timeout: 250 });
73+
} else {
74+
setTimeout(step, 16);
75+
}
76+
};
77+
78+
schedule();
4079
}
4180

4281
function onEntityChange(cb) {
@@ -70,7 +109,11 @@
70109
if (running) return;
71110
running = true;
72111

73-
const intervalMs = Number(options.intervalMs || 1000);
112+
const runtime = window.OIG_RUNTIME || {};
113+
const baseInterval = Number(options.intervalMs || 1000);
114+
const intervalMs = (runtime.isHaApp || runtime.isMobile)
115+
? Math.max(2000, baseInterval)
116+
: baseInterval;
74117
const prefixes = Array.isArray(options.prefixes) ? options.prefixes : [];
75118

76119
// Initial registration
@@ -80,9 +123,10 @@
80123
timer = setInterval(_tick, Math.max(250, intervalMs));
81124

82125
// Rescan prefixes occasionally (new entities, reloads)
126+
const rescanInterval = (runtime.isHaApp || runtime.isMobile) ? 60000 : 30000;
83127
rescanTimer = setInterval(() => {
84128
prefixes.forEach(registerPrefix);
85-
}, 30000);
129+
}, rescanInterval);
86130

87131
console.log('[StateWatcher] Started', { intervalMs, prefixes, watched: watched.size });
88132
}
@@ -104,4 +148,3 @@
104148
onEntityChange,
105149
};
106150
})();
107-

custom_components/oig_cloud/www/js/features/flow.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,20 @@ function getNodeCenters() {
785785

786786
// Animate particles - v2.0 with continuous normalization
787787
function animateFlow(data) {
788+
const runtime = window.OIG_RUNTIME || {};
789+
if (runtime.reduceMotion) {
790+
if (!runtime.particlesDisabled) {
791+
runtime.particlesDisabled = true;
792+
if (typeof stopAllParticleFlows === 'function') {
793+
stopAllParticleFlows();
794+
}
795+
const container = document.getElementById('particles');
796+
if (container) {
797+
container.innerHTML = '';
798+
}
799+
}
800+
return;
801+
}
788802
const { solarPower, solarPerc, batteryPower, gridPower, housePower, boilerPower, boilerMaxPower } = data;
789803

790804
// Use cached positions
@@ -1415,8 +1429,11 @@ async function loadData() {
14151429
}
14161430
}
14171431

1418-
await updatePlannerModeBadge();
1419-
await yieldIfNeeded();
1432+
const shouldUpdatePlanner = !isConstrainedRuntime || runtime.initialLoadComplete;
1433+
if (shouldUpdatePlanner) {
1434+
await updatePlannerModeBadge();
1435+
await yieldIfNeeded();
1436+
}
14201437

14211438
// Aktualizovat boiler mode (ve flow diagramu), ale zachovat třídu mode-changing pokud existuje
14221439
const boilerModeFlowData = await getSensorStringSafe(getSensorId('boiler_manual_mode'));
@@ -1605,17 +1622,20 @@ async function loadData() {
16051622
window.DashboardAnalytics.updateBatteryEfficiencyStats();
16061623
}
16071624

1608-
// Update planned consumption statistics
1609-
if (window.DashboardPricing?.updatePlannedConsumptionStats) {
1610-
window.DashboardPricing.updatePlannedConsumptionStats();
1611-
}
1625+
const pricingActive = typeof pricingTabActive !== 'undefined' ? pricingTabActive : false;
1626+
if (pricingActive) {
1627+
// Update planned consumption statistics
1628+
if (window.DashboardPricing?.updatePlannedConsumptionStats) {
1629+
window.DashboardPricing.updatePlannedConsumptionStats();
1630+
}
16121631

1613-
// Phase 2.6: Update what-if analysis and mode recommendations
1614-
if (window.DashboardPricing?.updateWhatIfAnalysis) {
1615-
window.DashboardPricing.updateWhatIfAnalysis();
1616-
}
1617-
if (window.DashboardPricing?.updateModeRecommendations) {
1618-
window.DashboardPricing.updateModeRecommendations();
1632+
// Phase 2.6: Update what-if analysis and mode recommendations
1633+
if (window.DashboardPricing?.updateWhatIfAnalysis) {
1634+
window.DashboardPricing.updateWhatIfAnalysis();
1635+
}
1636+
if (window.DashboardPricing?.updateModeRecommendations) {
1637+
window.DashboardPricing.updateModeRecommendations();
1638+
}
16191639
}
16201640

16211641
// Performance chart removed (legacy performance tracking)

0 commit comments

Comments
 (0)