Skip to content

Commit

Permalink
Working on Device Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed May 22, 2024
1 parent d4e475c commit 95b2207
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
15 changes: 12 additions & 3 deletions packages/dm-gui-components/src/Communication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@ import {
Snackbar,
} from '@mui/material';

import { Connection } from '@iobroker/adapter-react-v5';
import { AdminConnection } from '@iobroker/adapter-react-v5';
import type { ActionBase, ControlBase, ControlState } from '@iobroker/dm-utils/build/types/base';
import type { DeviceRefresh } from '@iobroker/dm-utils/build/types';

import { getTranslation } from './Utils';
import JsonConfig from './JsonConfig';
import type { ThemeName, ThemeType } from '@iobroker/adapter-react-v5/types';

export type CommunicationProps = {
/* socket object */
socket: Connection;
socket: AdminConnection;
/* Instance to communicate with device-manager backend, like `adapterName.X` */
selectedInstance: string; // adapterName.X
registerHandler?: (handler: null | ((command: string) => void)) => void;
themeName: ThemeName;
themeType: ThemeType;
isFloatComma: boolean;
dateFormat: string;
}

interface CommunicationForm {
Expand Down Expand Up @@ -358,14 +363,18 @@ class Communication<P extends CommunicationProps, S extends CommunicationState>
schema={this.state.form.schema}
data={this.state.form.data}
socket={this.props.socket}
onChange={(data: any) => {
onChange={(data: Record<string, any>) => {
console.log('handleFormChange', { data });
const form: CommunicationForm | null | undefined = { ...this.state.form };
if (form) {
form.data = data;
this.setState({ form });
}
}}
themeName={this.props.themeName}
themeType={this.props.themeType}
isFloatComma={this.props.isFloatComma}
dateFormat={this.props.dateFormat}
/>
</DialogContent>
<DialogActions>
Expand Down
13 changes: 11 additions & 2 deletions packages/dm-gui-components/src/DeviceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import {
Close as CloseIcon,
} from '@mui/icons-material';

import { Utils, Icon, Connection, I18n } from '@iobroker/adapter-react-v5';
import { Utils, Icon, AdminConnection, I18n } from '@iobroker/adapter-react-v5';
import type { DeviceDetails, DeviceInfo } from '@iobroker/dm-utils';
import type { ActionBase, ControlBase, ControlState } from '@iobroker/dm-utils/build/types/base';
import type { ThemeName, ThemeType } from '@iobroker/adapter-react-v5/types';

import DeviceActionButton from './DeviceActionButton';
import DeviceControlComponent from './DeviceControl';
Expand All @@ -37,14 +38,18 @@ interface DeviceCardProps {
id: string;
device: DeviceInfo;
instanceId: string;
socket: Connection;
socket: AdminConnection;
/* Instance, where the images should be uploaded to */
uploadImagesToInstance?: string;
deviceHandler: (deviceId: string, action: ActionBase<'api'>, refresh: () => void) => () => void;
controlHandler: (deviceId: string, control: ControlBase, state: ControlState) => () => Promise<ioBroker.State | null>;
controlStateHandler: (deviceId: string, control: ControlBase) => () => Promise<ioBroker.State | null>;
smallCards?: boolean;
alive: boolean;
themeName: ThemeName;
themeType: ThemeType;
isFloatComma: boolean;
dateFormat: string;
}

function getText(text: ioBroker.StringOrTranslated | undefined): string | undefined {
Expand Down Expand Up @@ -156,6 +161,10 @@ class DeviceCard extends Component<DeviceCardProps, DeviceCardState> {
schema={this.state.details.schema}
data={this.state.data}
onChange={(data: Record<string, any>) => this.setState({ data })}
themeName={this.props.themeName}
themeType={this.props.themeType}
isFloatComma={this.props.isFloatComma}
dateFormat={this.props.dateFormat}
/>
</DialogContent>
<DialogActions>
Expand Down
4 changes: 4 additions & 0 deletions packages/dm-gui-components/src/DeviceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ export default class DeviceList extends Communication<DeviceListProps, DeviceLis
controlHandler={this.controlHandler}
controlStateHandler={this.controlStateHandler}
socket={this.props.socket}
themeName={this.props.themeName}
themeType={this.props.themeType}
isFloatComma={this.props.isFloatComma}
dateFormat={this.props.dateFormat}
/>);
}

Expand Down
16 changes: 12 additions & 4 deletions packages/dm-gui-components/src/JsonConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import React, { useState } from 'react';
import { Connection, JsonConfigComponent } from '@iobroker/adapter-react-v5';
import { AdminConnection, JsonConfigComponent } from '@iobroker/adapter-react-v5';
import type { ThemeName, ThemeType } from '@iobroker/adapter-react-v5/types';

interface JsonConfigProps {
instanceId: string;
socket: Connection;
socket: AdminConnection;
schema: Record<string, any>;
data: Record<string, any>;
onChange: (data: Record<string, any>) => void;
themeName: ThemeName;
themeType: ThemeType;
isFloatComma?: boolean;
dateFormat?: string;
}

export default function JsonConfig(props: JsonConfigProps): React.JSX.Element | null {
const {
instanceId, socket, schema, data, onChange,
} = props;
console.log('JsonConfig', props);
const [error, setError] = useState();
const [error, setError] = useState(false);

if (schema === undefined) {
return null;
Expand All @@ -31,9 +36,12 @@ export default function JsonConfig(props: JsonConfigProps): React.JSX.Element |
schema={schema}
data={data}
onError={setError}
// @ts-expect-error types needed
onChange={_data => onChange(_data)}
embedded
themeName={props.themeName}
themeType={props.themeType}
isFloatComma={props.isFloatComma === undefined ? this.props.socket.systemConfig.common.isFloatComma : props.isFloatComma}
dateFormat={props.dateFormat === undefined ? this.props.socket.systemConfig.common.dateFormat : props.dateFormat}
/>
</>;

Expand Down

0 comments on commit 95b2207

Please sign in to comment.