feat: basic device discover parameters

This commit is contained in:
Leandro Antônio Farias Machado 2023-07-27 11:55:39 -03:00
parent 51acf7569f
commit f01f662fa4

View File

@ -10,9 +10,13 @@ import {
Collapse, Collapse,
Box, Box,
Tabs, Tabs,
Tab Tab,
ListItemIcon,
ListItemAvatar,
Avatar
} from '@mui/material'; } from '@mui/material';
import CircularProgress from '@mui/material/CircularProgress'; import CircularProgress from '@mui/material/CircularProgress';
import PlusCircleIcon from '@heroicons/react/24/outline/PlusCircleIcon';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
@ -52,7 +56,7 @@ const getDeviceParameters = async (raw) =>{
initialize( initialize(
JSON.stringify({ JSON.stringify({
"obj_paths": ["Device."], "obj_paths": ["Device."],
"first_level_only" : false, "first_level_only" : true,
"return_commands" : false, "return_commands" : false,
"return_events" : false, "return_events" : false,
"return_params" : true "return_params" : true
@ -83,31 +87,22 @@ const getDeviceParameters = async (raw) =>{
// }) // })
// } // }
// const updateDeviceParameters = async (param,) => { const updateDeviceParameters = async (param) => {
// let raw = JSON.stringify({ let raw = JSON.stringify({
// "obj_paths": [param], "obj_paths": [param],
// "first_level_only" : true, "first_level_only" : true,
// "return_commands" : false, "return_commands" : true,
// "return_events" : false, "return_events" : true,
// "return_params" : true "return_params" : true
// }) })
// let content = await getDeviceParameters(raw) let content = await getDeviceParameters(raw)
// console.log(content) console.log(content)
// setDeviceParameters(prevState => { setDeviceParameters(content)
// return {...prevState, req_obj_results: [ }
// {
// supported_objs:[ ...prevState.req_obj_results[0].
// supported_objs][index]
// .supported_params:[]
// }
// ]
// }
// })
// }
const showParameters = () => { const showParameters = () => {
console.log(deviceParameters) console.log(deviceParameters)
@ -117,13 +112,13 @@ const getDeviceParameters = async (raw) =>{
<ListItem <ListItem
key={x.supported_obj_path} key={x.supported_obj_path}
divider={true} divider={true}
// secondaryAction={ secondaryAction={
// <IconButton /*onClick={()=>updateDeviceParameters(x.supported_obj_path, index)}*/> <IconButton onClick={()=>updateDeviceParameters(x.supported_obj_path)}>
// <SvgIcon> <SvgIcon>
// <PlusCircleIcon></PlusCircleIcon> <PlusCircleIcon></PlusCircleIcon>
// </SvgIcon> </SvgIcon>
// </IconButton> </IconButton>
// } }
sx={{ sx={{
boxShadow: 'rgba(149, 157, 165, 0.2) 0px 0px 5px;' boxShadow: 'rgba(149, 157, 165, 0.2) 0px 0px 5px;'
}} }}
@ -156,6 +151,52 @@ const getDeviceParameters = async (raw) =>{
</List> </List>
}) })
} }
{ x.supported_commands &&
x.supported_commands.map((y)=>{
return <List
component="div"
disablePadding
dense={true}
key={y.command_name}
>
<ListItem
key={i}
divider={true}
sx={{
boxShadow: 'rgba(149, 157, 165, 0.2) 0px 0px 5px;',
pl: 4
}}
>
<ListItemText
primary={y.command_name}
/>
</ListItem>
</List>
})
}
{ x.supported_events &&
x.supported_events.map((y)=>{
return <List
component="div"
disablePadding
dense={true}
key={y.event_name}
>
<ListItem
key={i}
divider={true}
sx={{
boxShadow: 'rgba(149, 157, 165, 0.2) 0px 0px 5px;',
pl: 4
}}
>
<ListItemText
primary={y.event_name}
/>
</ListItem>
</List>
})
}
</List>) </List>)
}) })
} }