Skip to content

Commit

Permalink
fix(AddDeviceToGroup): fix selection of non default endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
nurikk committed Nov 25, 2021
1 parent 78730a5 commit bb8a211
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/components/groups/AddDeviceToGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@ import { getEndpoints } from "../../utils";
import EndpointPicker from "../endpoint-picker";
import DevicePicker from "../device-picker";
import { useTranslation } from "react-i18next";

import { WithDevices } from "../../store";


type AddDeviceToGroupState = {
device?: string;
endpoint?: Endpoint;
}

type AddDeviceToGroupProps = {
group: Group;
addDeviceToGroup(deviceName: string, groupName: string): void;
} & WithDevices;

export function AddDeviceToGroup(props: AddDeviceToGroupProps): JSX.Element {
const [state, setState] = useState<AddDeviceToGroupState>({});
const [endpoint, setEndpoint] = useState<Endpoint>("");
const [device, setDevice] = useState<string>("");
const { addDeviceToGroup, group, devices } = props;
const { device, endpoint } = state;


const deviceObj = devices[device as string];
const endpoints = getEndpoints(deviceObj);
Expand All @@ -33,11 +27,12 @@ export function AddDeviceToGroup(props: AddDeviceToGroupProps): JSX.Element {
};
const onDeviceSelect = (d: Device): void => {
const eps = getEndpoints(d);
setState({ device: d.ieee_address, endpoint: eps[0] });
setDevice(d.ieee_address)
setEndpoint(eps[0]);
};

const onEpChange = (ep: Endpoint): void => {
setState({ endpoint: ep });
setEndpoint(ep);
};

return <>
Expand Down

0 comments on commit bb8a211

Please sign in to comment.