Skip to content

Commit 793926c

Browse files
committed
Change device grouping field from type to group, add HVAC action mapper
1 parent 0da0b7c commit 793926c

5 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/pages/Devices.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ErrorMessage from '../widgets/ErrorMessage.jsx';
1010
import { useVariant } from '../hooks/useVariant.js';
1111

1212
const Devices = ({
13-
deviceType,
13+
deviceGroup,
1414
deviceActionMapper,
1515
}) => {
1616
const { t } = useTranslation();
@@ -24,7 +24,7 @@ const Devices = ({
2424
});
2525

2626
const filteredDevices = useMemo(() =>
27-
devices ? devices.filter(device => device.type === deviceType) : [], [deviceType, devices]);
27+
devices ? devices.filter(device => device.group === deviceGroup) : [], [deviceGroup, devices]);
2828

2929
const variant = useVariant();
3030
const isInitLab = variant === 'initlab';
@@ -58,7 +58,7 @@ const Devices = ({
5858
}) : <Col>
5959
<Card>
6060
<Card.Body className="d-flex flex-column flex-lg-row gap-4">
61-
{t('views.' + deviceType + '.no_access')}
61+
{t('views.' + deviceGroup + '.no_access')}
6262
</Card.Body>
6363
</Card>
6464
</Col>}
@@ -70,7 +70,7 @@ const Devices = ({
7070
};
7171

7272
Devices.propTypes = {
73-
deviceType: PropTypes.string.isRequired,
73+
deviceGroup: PropTypes.string.isRequired,
7474
deviceActionMapper: PropTypes.func.isRequired,
7575
};
7676

src/pages/Doors.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getDoorActions } from '../utils/device.js';
22
import Devices from './Devices.jsx';
33

44
const Doors = () => {
5-
return (<Devices deviceType="door" deviceActionMapper={getDoorActions} />);
5+
return (<Devices deviceGroup="door" deviceActionMapper={getDoorActions} />);
66
};
77

88
export default Doors;

src/pages/Hvac.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getDeviceActions } from '../utils/device.js';
1+
import { getHvacActions } from '../utils/device.js';
22
import Devices from './Devices.jsx';
33

44
const Hvac = () => {
5-
return (<Devices deviceType="hvac" deviceActionMapper={getDeviceActions} />);
5+
return (<Devices deviceGroup="hvac" deviceActionMapper={getHvacActions} />);
66
};
77

88
export default Hvac;

src/pages/Lights.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getLightActions } from '../utils/device.js';
22
import Devices from './Devices.jsx';
33

44
const Lights = () => {
5-
return (<Devices deviceType="light" deviceActionMapper={getLightActions} />);
5+
return (<Devices deviceGroup="light" deviceActionMapper={getLightActions} />);
66
};
77

88
export default Lights;

src/utils/device.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ export function getLightActions(light) {
4242

4343
return actions.filter(action => action !== (activityStatus ? 'turn_on' : 'turn_off'));
4444
}
45+
46+
export function getHvacActions(device) {
47+
if (device.type === 'switch') {
48+
return getLightActions(device);
49+
}
50+
51+
return getDeviceActions(device);
52+
}

0 commit comments

Comments
 (0)