Skip to content

Commit

Permalink
fix: match 2.0.0 permit join API (#2158)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec authored and Koenkk committed Dec 2, 2024
1 parent 5489e3b commit e6679e9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/actions/BridgeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { Device } from '../types';
import store from '../store';

export interface BridgeApi {
setPermitJoin(permit: boolean, device: Device): Promise<void>;
setPermitJoin(time: number, device: Device): Promise<void>;
updateBridgeConfig(options: unknown): Promise<void>;
restartBridge(): Promise<void>;
requestBackup(): Promise<void>;
addInstallCode(installCode: string): Promise<void>;
}


const setPermitJoin = (_state, permit = true, device?: Device, time = 254): Promise<void> => {
return api.send("bridge/request/permit_join", { value: permit, time, device: device?.friendly_name });
const setPermitJoin = (_state, time = 254, device?: Device): Promise<void> => {
return api.send("bridge/request/permit_join", { time, device: device?.friendly_name });
}

export default {
Expand All @@ -29,6 +29,6 @@ export default {
},
async addInstallCode(_state, installCode: string): Promise<void> {
await api.send('bridge/request/install_code/add', { value: installCode });
return setPermitJoin(_state, true)
return setPermitJoin(_state, 254)
}
}
5 changes: 3 additions & 2 deletions src/components/navbar/StartStopJoinButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export function StartStopJoinButton({ devices, setPermitJoin, bridgeInfo }: Star
const { t } = useTranslation(['navbar']);
const { ref, isComponentVisible, setIsComponentVisible } = useComponentVisible(false);
const [selectedRouter, setSelectedRouter] = useState<Device>({} as Device);
const { permit_join: permitJoin, permit_join_timeout: permitJoinTimeout } = bridgeInfo;
const { permit_join_timeout: permitJoinTimeout } = bridgeInfo;
const permitJoin = permitJoinTimeout > 0;

const selectAndHide = (device: Device) => {
setSelectedRouter(device);
Expand All @@ -36,7 +37,7 @@ export function StartStopJoinButton({ devices, setPermitJoin, bridgeInfo }: Star
));

const onBtnClick = () => {
setPermitJoin(!permitJoin, selectedRouter);
setPermitJoin(permitJoin ? 0 : 254, selectedRouter);
};
const permitJoinTimer = (
<>
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export type BridgeState = 'online' | 'offline';
export interface BridgeInfo {
config: Z2MConfig;
config_schema: JSONSchema7;
permit_join: boolean;
permit_join_timeout: number;
commit?: string;
version?: string;
Expand Down

0 comments on commit e6679e9

Please sign in to comment.