device values table reformatting

This commit is contained in:
proddy
2021-04-06 11:18:44 +02:00
parent 33c3ef64e9
commit 9dbc6d4d8f
5 changed files with 44 additions and 55 deletions

View File

@@ -8,6 +8,8 @@ import {
import RefreshIcon from "@material-ui/icons/Refresh"; import RefreshIcon from "@material-ui/icons/Refresh";
import ListIcon from "@material-ui/icons/List"; import ListIcon from "@material-ui/icons/List";
import IconButton from '@material-ui/core/IconButton';
import EditIcon from '@material-ui/icons/Edit';
import { redirectingAuthorizedFetch, withAuthenticatedContext, AuthenticatedContextProps } from "../authentication"; import { redirectingAuthorizedFetch, withAuthenticatedContext, AuthenticatedContextProps } from "../authentication";
import { RestFormProps, FormButton } from "../components"; import { RestFormProps, FormButton } from "../components";
@@ -44,11 +46,10 @@ interface EMSESPDevicesFormState {
confirmScanDevices: boolean; confirmScanDevices: boolean;
processing: boolean; processing: boolean;
deviceData?: EMSESPDeviceData; deviceData?: EMSESPDeviceData;
selectedDevice?: number;
} }
type EMSESPDevicesFormProps = RestFormProps<EMSESPDevices> & type EMSESPDevicesFormProps = RestFormProps<EMSESPDevices> & AuthenticatedContextProps & WithWidthProps;
AuthenticatedContextProps &
WithWidthProps;
function formatTemp(t: string) { function formatTemp(t: string) {
if (t == null) { if (t == null) {
@@ -67,9 +68,20 @@ function formatUnit(u: string) {
class EMSESPDevicesForm extends Component<EMSESPDevicesFormProps, EMSESPDevicesFormState> { class EMSESPDevicesForm extends Component<EMSESPDevicesFormProps, EMSESPDevicesFormState> {
state: EMSESPDevicesFormState = { state: EMSESPDevicesFormState = {
confirmScanDevices: false, confirmScanDevices: false,
processing: false, processing: false
}; };
sendCommand = (i: any) => {
const name = this.state.deviceData?.data[i+2];
const value = this.state.deviceData?.data[i];
const deviceType = this.state.selectedDevice;
console.log("type: " + deviceType + " name: " + name + " value: " + value);
// this.setState({
// user: undefined
// });
}
noDevices = () => { noDevices = () => {
return this.props.data.devices.length === 0; return this.props.data.devices.length === 0;
}; };
@@ -95,50 +107,26 @@ class EMSESPDevicesForm extends Component<EMSESPDevicesFormProps, EMSESPDevicesF
size="small" size="small"
padding={isWidthDown("xs", width!) ? "none" : "default"} padding={isWidthDown("xs", width!) ? "none" : "default"}
> >
<TableHead>
<TableRow>
<StyledTableCell>Type</StyledTableCell>
<StyledTableCell align="center">Brand</StyledTableCell>
<StyledTableCell align="center">Model</StyledTableCell>
<StyledTableCell align="center">Device ID</StyledTableCell>
<StyledTableCell align="center">Product ID</StyledTableCell>
<StyledTableCell align="center">Version</StyledTableCell>
<StyledTableCell></StyledTableCell>
</TableRow>
</TableHead>
<TableBody> <TableBody>
{data.devices.sort(compareDevices).map((device) => ( {data.devices.sort(compareDevices).map((device) => (
<TableRow <TableRow
hover hover
key={device.id} key={device.id}
onClick={() => this.handleRowClick(device.id)} onClick={() => this.handleRowClick(device)}
> >
<TableCell component="th" scope="row"> <TableCell>
<Tooltip <Tooltip
title="click for details..." title={"DeviceID:0x" + ("00" + device.deviceid.toString(16).toUpperCase()).slice(-2) + " ProductID:" + device.productid + " Version:" + device.version}
arrow arrow placement="right-end"
placement="right-end"
> >
<Button <Button
startIcon={<ListIcon />} startIcon={<ListIcon />} size="small" variant="outlined"
size="small"
variant="outlined"
> >
{device.type} {device.type}
</Button> </Button>
</Tooltip> </Tooltip>
</TableCell> </TableCell>
<TableCell align="center">{device.brand}</TableCell> <TableCell>{device.brand + " " + device.name} </TableCell>
<TableCell align="center">{device.name}</TableCell>
<TableCell align="center">
0x
{("00" + device.deviceid.toString(16).toUpperCase()).slice(
-2
)}
</TableCell>
<TableCell align="center">{device.productid}</TableCell>
<TableCell align="center">{device.version}</TableCell>
<TableCell></TableCell>
</TableRow> </TableRow>
))} ))}
</TableBody> </TableBody>
@@ -148,13 +136,10 @@ class EMSESPDevicesForm extends Component<EMSESPDevicesFormProps, EMSESPDevicesF
<Box <Box
bgcolor="error.main" bgcolor="error.main"
color="error.contrastText" color="error.contrastText"
p={2} p={2} mt={2} mb={2}
mt={2}
mb={2}
> >
<Typography variant="body1"> <Typography variant="body1">
No EMS devices found. Check the connections and for possible Tx No EMS devices found. Check the connections and for possible Tx errors.
errors.
</Typography> </Typography>
</Box> </Box>
)} )}
@@ -213,8 +198,7 @@ class EMSESPDevicesForm extends Component<EMSESPDevicesFormProps, EMSESPDevicesF
> >
<DialogTitle>Confirm Scan Devices</DialogTitle> <DialogTitle>Confirm Scan Devices</DialogTitle>
<DialogContent dividers> <DialogContent dividers>
Are you sure you want to initiate a scan on the EMS bus for all new Are you sure you want to initiate a scan on the EMS bus for all new devices?
devices?
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button <Button
@@ -268,11 +252,11 @@ class EMSESPDevicesForm extends Component<EMSESPDevicesFormProps, EMSESPDevicesF
}); });
}; };
handleRowClick = (id: any) => { handleRowClick = (device: any) => {
this.setState({ deviceData: undefined }); this.setState({ selectedDevice: device.id, deviceData: undefined });
redirectingAuthorizedFetch(DEVICE_DATA_ENDPOINT, { redirectingAuthorizedFetch(DEVICE_DATA_ENDPOINT, {
method: "POST", method: "POST",
body: JSON.stringify({ id: id }), body: JSON.stringify({ id: device.id }),
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
@@ -321,16 +305,23 @@ class EMSESPDevicesForm extends Component<EMSESPDevicesFormProps, EMSESPDevicesF
size="small" size="small"
padding={isWidthDown("xs", width!) ? "none" : "default"} padding={isWidthDown("xs", width!) ? "none" : "default"}
> >
<TableHead></TableHead> <TableHead>
</TableHead>
<TableBody> <TableBody>
{deviceData.data.map((item, i) => { {deviceData.data.map((item, i) => {
if (i % 3) { if (i % 3) {
return null; return null;
} else { } else {
return ( return (
<TableRow key={i}> <TableRow hover key={i}>
<TableCell component="th" scope="row">{deviceData.data[i + 2]}</TableCell> <TableCell padding="checkbox" style={{ width: 18 }} >
<TableCell align="right">{deviceData.data[i]}{formatUnit(deviceData.data[i + 1])}</TableCell> <IconButton edge="start" size="small" aria-label="Edit"
onClick={() => this.sendCommand(i)}>
<EditIcon fontSize="small"/>
</IconButton>
</TableCell>
<TableCell padding="none" component="th" scope="row">{deviceData.data[i + 2]}</TableCell>
<TableCell padding="none" align="right">{deviceData.data[i]}{formatUnit(deviceData.data[i + 1])}</TableCell>
</TableRow> </TableRow>
); );
} }

View File

@@ -122,9 +122,7 @@ class ManageUsersForm extends React.Component<ManageUsersFormProps, ManageUsersF
{user.username} {user.username}
</TableCell> </TableCell>
<TableCell align="center"> <TableCell align="center">
{ {user.admin ? <CheckIcon /> : <CloseIcon />}
user.admin ? <CheckIcon /> : <CloseIcon />
}
</TableCell> </TableCell>
<TableCell align="center"> <TableCell align="center">
<IconButton size="small" aria-label="Delete" onClick={() => this.removeUser(user)}> <IconButton size="small" aria-label="Delete" onClick={() => this.removeUser(user)}>

View File

@@ -119,13 +119,13 @@ const emsesp_settings = {
}; };
const emsesp_alldevices = { const emsesp_alldevices = {
"devices": [{ "devices": [{
"id": 1, "type": "Thermostat", "brand": "---", "name": "RC20/Moduline 300", "id": 1, "type": "Thermostat", "brand": "", "name": "RC20/Moduline 300",
"deviceid": 23, "productid": 77, "version": "03.03" "deviceid": 23, "productid": 77, "version": "03.03"
}, { }, {
"id": 2, "type": "Boiler", "brand": "Nefit", "name": "GBx72/Trendline/Cerapur/Greenstar Si/27i", "id": 2, "type": "Boiler", "brand": "Nefit", "name": "GBx72/Trendline/Cerapur/Greenstar Si/27i",
"deviceid": 8, "productid": 123, "version": "06.01" "deviceid": 8, "productid": 123, "version": "06.01"
}, { }, {
"id": 3, "type": "Controller", "brand": "---", "name": "BC10", "id": 3, "type": "Controller", "brand": "", "name": "BC10",
"deviceid": 9, "productid": 190, "version": "01.03" "deviceid": 9, "productid": 190, "version": "01.03"
}], }],
"sensors": [] "sensors": []

View File

@@ -149,7 +149,7 @@ std::string EMSdevice::brand_to_string() const {
break; break;
case EMSdevice::Brand::NO_BRAND: case EMSdevice::Brand::NO_BRAND:
default: default:
return read_flash_string(F("---")); return read_flash_string(F(""));
break; break;
} }

View File

@@ -1,2 +1,2 @@
#define EMSESP_APP_VERSION "3.0.2b1" #define EMSESP_APP_VERSION "3.0.3b0"
#define EMSESP_PLATFORM "ESP32" #define EMSESP_PLATFORM "ESP32"