mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-17 10:00:46 -04:00
granpa!! (auto lights on)
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -5,7 +5,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>webui</title>
|
<title>webui</title>
|
||||||
<script type="module" crossorigin src="/assets/index-BSgR8Uj3.js"></script>
|
<script type="module" crossorigin src="/assets/index-BXPUoQFz.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-CCqAmxiE.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-CCqAmxiE.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { useCommandPipeline } from './commandPipeline.js';
|
|||||||
import { DEFAULT_KEYMAP, DEFAULT_MACROS } from './constants.js';
|
import { DEFAULT_KEYMAP, DEFAULT_MACROS } from './constants.js';
|
||||||
import { canonicalizeKeyInput } from './keymapUtils.js';
|
import { canonicalizeKeyInput } from './keymapUtils.js';
|
||||||
import { useSettingsNamespace } from '../settings/index.js';
|
import { useSettingsNamespace } from '../settings/index.js';
|
||||||
|
import { useSession } from '../context/SessionContext.jsx';
|
||||||
|
|
||||||
const ControlSystemContext = createContext(null);
|
const ControlSystemContext = createContext(null);
|
||||||
|
|
||||||
@@ -24,16 +25,33 @@ function clampServoAngle(config, value) {
|
|||||||
export function ControlSystemProvider({ children }) {
|
export function ControlSystemProvider({ children }) {
|
||||||
const pipeline = useCommandPipeline();
|
const pipeline = useCommandPipeline();
|
||||||
const [state, dispatch] = useReducer(controlReducer, initialControlState);
|
const [state, dispatch] = useReducer(controlReducer, initialControlState);
|
||||||
|
const prevModeRef = useRef(initialControlState.mode);
|
||||||
const servoAngleRef = useRef(initialControlState.camera.angle);
|
const servoAngleRef = useRef(initialControlState.camera.angle);
|
||||||
const {
|
const {
|
||||||
value: controlSettings,
|
value: controlSettings,
|
||||||
save: saveControlSettings,
|
save: saveControlSettings,
|
||||||
} = useSettingsNamespace('controls', { keymap: DEFAULT_KEYMAP, macros: DEFAULT_MACROS });
|
} = useSettingsNamespace('controls', { keymap: DEFAULT_KEYMAP, macros: DEFAULT_MACROS });
|
||||||
|
const { session, homeAssistantSetState } = useSession();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch({ type: 'control/set-rover', payload: pipeline.roverId });
|
dispatch({ type: 'control/set-rover', payload: pipeline.roverId });
|
||||||
}, [pipeline.roverId]);
|
}, [pipeline.roverId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const prevMode = prevModeRef.current;
|
||||||
|
prevModeRef.current = state.mode;
|
||||||
|
if (prevMode !== 'drive' && state.mode === 'drive' && session?.homeAssistant?.entities) {
|
||||||
|
const targets = session.homeAssistant.entities.filter(
|
||||||
|
(ent) => ent.type === 'light' && ent.available !== false && ent.state !== 'on',
|
||||||
|
);
|
||||||
|
if (targets.length > 0) {
|
||||||
|
targets.forEach((ent) => {
|
||||||
|
homeAssistantSetState(ent.id, 'on').catch(() => {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [state.mode, session?.homeAssistant?.entities, homeAssistantSetState]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const mergedKeymap = { ...DEFAULT_KEYMAP, ...(controlSettings?.keymap || {}) };
|
const mergedKeymap = { ...DEFAULT_KEYMAP, ...(controlSettings?.keymap || {}) };
|
||||||
dispatch({ type: 'control/set-keymap', payload: mergedKeymap });
|
dispatch({ type: 'control/set-keymap', payload: mergedKeymap });
|
||||||
|
|||||||
Reference in New Issue
Block a user