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 Oct 15, 2024
1 parent 65b2965 commit 6e31bc2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 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
3 changes: 0 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,11 @@ export interface BridgeConfig {
coordinator: Coordinator;
network: Network;
log_level: string;
permit_join: boolean;

}
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 6e31bc2

Please sign in to comment.