Skip to content

Commit 1e86287

Browse files
committed
fix: avoid cast tv wakeups
1 parent e68e494 commit 1e86287

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

modules/services/hass/_domains/conversation.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ _: {
182182
speech.text = "Turning on the TV.";
183183
action = [
184184
{
185-
action = "media_player.turn_on";
186-
target.entity_id = "media_player.tv";
185+
action = "script.tv_on";
187186
}
188187
];
189188
};

modules/services/hass/_domains/tv.nix

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
let
44
inherit (import ../_lib.nix) ensureEnabled;
55

6+
tvEntity = "media_player.living_room";
7+
68
# --- Helper functions ---
79
tvAction = action: {
810
inherit action;
9-
target.entity_id = "media_player.tv";
11+
target.entity_id = tvEntity;
1012
};
1113

1214
tvOn = tvAction "media_player.turn_on";
@@ -66,7 +68,7 @@ in
6668
id = "tv_idle_auto_off";
6769
trigger = {
6870
platform = "state";
69-
entity_id = "media_player.tv";
71+
entity_id = tvEntity;
7072
to = "idle";
7173
"for".hours = 2;
7274
};
@@ -136,7 +138,7 @@ in
136138
id = "count_tv_sessions";
137139
trigger = {
138140
platform = "state";
139-
entity_id = "media_player.tv";
141+
entity_id = tvEntity;
140142
to = "playing";
141143
};
142144
action = [

modules/services/hass/_tests/eval-automations.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ let
2121
haConfig = nixosConfig.config.services.home-assistant.config;
2222
automations = haConfig.automation;
2323
scenes = haConfig.scene;
24+
scripts = haConfig.script;
2425

2526
findAutomation =
2627
id:
@@ -82,6 +83,8 @@ let
8283
hasActionVariable =
8384
actions: variableName: any (a: a ? variables && builtins.hasAttr variableName a.variables) actions;
8485

86+
hasTargetEntity = actions: entityId: any (a: (a.target.entity_id or null) == entityId) actions;
87+
8588
hasTimeGuard =
8689
conditions: target:
8790
any (c: (c.condition or null) == "time" && (c.after or null) == target) conditions;
@@ -142,6 +145,7 @@ let
142145
alDaytimeSleepCorrection = findAutomation "al_daytime_sleep_correction";
143146
entranceOccupancyNightLight = findAutomation "entrance_occupancy_night_light";
144147
arrivalFlashWallLamp = findAutomation "arrival_flash_wall_lamp";
148+
tvOnScript = scripts.tv_on or null;
145149

146150
# Must stay removed
147151
goodMorningBothAwake = findAutomation "good_morning_both_awake";
@@ -222,6 +226,14 @@ let
222226
test = syncIphoneAlarm8sleep != null && (syncIphoneAlarm8sleep.initial_state or null) == false;
223227
msg = "automation 'sync_iphone_alarm_8sleep' should remain present but declaratively disabled until an iOS alarm source exists";
224228
}
229+
{
230+
test =
231+
tvOnScript != null
232+
&& hasActionCall (toList (tvOnScript.sequence or [ ])) "media_player.turn_on"
233+
&& hasTargetEntity (toList (tvOnScript.sequence or [ ])) "media_player.living_room"
234+
&& !(hasTargetEntity (toList (tvOnScript.sequence or [ ])) "media_player.tv");
235+
msg = "script.tv_on must target Living Room Apple TV, not Cast media_player.tv";
236+
}
225237
{
226238
test = sleepFocusOffEdmund != null;
227239
msg = "automation 'sleep_focus_off_stop_edmund' missing";

0 commit comments

Comments
 (0)