Skip to content

Commit

Permalink
add rain detection control
Browse files Browse the repository at this point in the history
  • Loading branch information
firsttris committed Dec 29, 2023
1 parent 0ac21a8 commit 36fe00f
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 118 deletions.
13 changes: 8 additions & 5 deletions src/app/ChannelsForType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import {
styled,
} from '@mui/material';
import { useState } from 'react';
import { Channel, ChannelType } from './../hooks/useApi';
import { FloorControl } from './FloorControl';
import { SwitchControl } from './SwitchControl';
import { ThermostatControl } from './ThermostatControl';
import { BlindsControl } from './BlindsControl';
import { FloorControl } from './controls/FloorControl';
import { SwitchControl } from './controls/SwitchControl';
import { ThermostatControl } from './controls/ThermostatControl';
import { BlindsControl } from './controls/BlindsControl';
import { useTranslations } from './../i18n/utils';
import { Icon } from '@iconify/react';
import { Channel, ChannelType } from './../types/types';
import { RainDetectionControl } from './controls/RainDetectionControl';


interface ExpandMoreProps {
Expand Down Expand Up @@ -46,6 +47,8 @@ const getControlComponent = (channel: Channel, refetch: () => void) => {
return <ThermostatControl channel={channel} />;
case ChannelType.BLIND_VIRTUAL_RECEIVER:
return <BlindsControl channel={channel} />;
case ChannelType.RAIN_DETECTION_TRANSMITTER:
return <RainDetectionControl channel={channel} />;
default:
return (
<Box>
Expand Down
Empty file.
10 changes: 5 additions & 5 deletions src/app/BlindsControl.tsx → src/app/controls/BlindsControl.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Box, CardContent } from '@mui/material';
import {
BlindVirtualReceiverChannel,
useSetValueMutation,
} from '../hooks/useApi';
import { CircularProgressWithLabel } from './components/CircularProgressWithLabel';
import { StyledIconButton } from './components/StyledIcons';
import { ChannelHeader } from './components/ChannelHeader';
} from '../../hooks/useApi';
import { CircularProgressWithLabel } from '../components/CircularProgressWithLabel';
import { StyledIconButton } from '../components/StyledIcons';
import { ChannelHeader } from '../components/ChannelHeader';
import { BlindVirtualReceiverChannel } from 'src/types/types';

interface ControlProps {
channel: BlindVirtualReceiverChannel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
LinearProgress,
Typography,
} from '@mui/material';
import { FloorClimateControlTransceiverChannel } from 'src/hooks/useApi';
import { StyledHeaderIcon } from './components/StyledIcons';
import { ChannelHeader } from './components/ChannelHeader';
import { StyledHeaderIcon } from '../components/StyledIcons';
import { ChannelHeader } from '../components/ChannelHeader';
import { FloorClimateControlTransceiverChannel } from 'src/types/types';

interface FloorControlProps {
channel: FloorClimateControlTransceiverChannel;
Expand Down
58 changes: 58 additions & 0 deletions src/app/controls/RainDetectionControl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Box, CardHeader, Typography, styled } from '@mui/material';
import { RainDesctionTransmitterChannel } from './../../types/types';
import { StyledHeaderIcon } from '../components/StyledIcons';

const StyledBox = styled(Box)({
display: 'flex',
flexDirection: 'column',
});

const StyledIconBox = styled(Box)({
display: 'flex',
alignItems: 'center',
gap: '5px',
});


interface RainDetectionControlProps {
channel: RainDesctionTransmitterChannel;
}

export const RainDetectionControl: React.FC<RainDetectionControlProps> = ({
channel,
}) => {
const {
datapoints: { HEATER_STATE, RAINING },
} = channel;

const isRaining = RAINING === 'true';
const isHeating = HEATER_STATE === 'true';

return (
<CardHeader
title={
<StyledBox>
<StyledIconBox>
{isRaining ? (
<StyledHeaderIcon icon="mdi:weather-heavy-rain" color="#0077B6" />
) : (
<StyledHeaderIcon icon="mdi:clouds" />
)}
<Typography variant="caption">{isRaining ? 'Raining' : 'Not Raining'}</Typography>
</StyledIconBox>
<StyledIconBox>
{isHeating ? (
<StyledHeaderIcon
icon="material-symbols:mode-heat"
color="#FF4500"
/>
) : (
<StyledHeaderIcon icon="material-symbols:mode-heat-off" />
)}
<Typography variant="caption">{isHeating ? 'Heating' : 'Not Heating'}</Typography>
</StyledIconBox>
</StyledBox>
}
/>
);
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { styled } from '@mui/system';
import { Box } from '@mui/material';
import {
SwitchVirtualReceiverChannel,
useSetValueMutation,
} from '../hooks/useApi';
import { ChannelHeader } from './components/ChannelHeader';
} from '../../hooks/useApi';
import { ChannelHeader } from '../components/ChannelHeader';
import { SwitchVirtualReceiverChannel } from 'src/types/types';

interface ControlProps {
channel: SwitchVirtualReceiverChannel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Box, Slider, Typography, styled } from '@mui/material';

import {
HeatingClimateControlTransceiverChannel,
useSetValueMutation,
} from '../hooks/useApi';
} from '../../hooks/useApi';
import { useEffect, useState } from 'react';
import { CircularProgressWithLabel } from './components/CircularProgressWithLabel';
import { StyledHeaderIcon, StyledIconButton } from './components/StyledIcons';
import { ChannelHeader } from './components/ChannelHeader';
import { CircularProgressWithLabel } from '../components/CircularProgressWithLabel';
import { StyledHeaderIcon, StyledIconButton } from '../components/StyledIcons';
import { ChannelHeader } from '../components/ChannelHeader';
import { HeatingClimateControlTransceiverChannel } from 'src/types/types';

interface ControlProps {
channel: HeatingClimateControlTransceiverChannel;
Expand Down
97 changes: 1 addition & 96 deletions src/hooks/useApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,102 +5,7 @@ import regaGetRoomsScript from './../rega/getRooms.tcl';
import regaGetChannelsScript from './../rega/getChannelsForRoomId.tcl';
import { useCheckSession } from './useCheckSession';
import { useMemo } from 'react';

export enum ChannelType {
SWITCH_VIRTUAL_RECEIVER = "SWITCH_VIRTUAL_RECEIVER",
BLIND_VIRTUAL_RECEIVER = "BLIND_VIRTUAL_RECEIVER",
HEATING_CLIMATECONTROL_TRANSCEIVER = "HEATING_CLIMATECONTROL_TRANSCEIVER",
CLIMATECONTROL_FLOOR_TRANSCEIVER = "CLIMATECONTROL_FLOOR_TRANSCEIVER"
}

export type SwitchVirtualReceiverDatapoint = {
COMBINED_PARAMETER: string;
ON_TIME: string;
PROCESS: string;
SECTION: string;
SECTION_STATUS: string;
STATE: string;
};

export type BlindVirtualReceiverDatapoint = {
ACTIVITY_STATE: string;
COMBINED_PARAMETER: string;
LEVEL: string;
LEVEL_2: string;
LEVEL_2_STATUS: string;
LEVEL_STATUS: string;
PROCESS: string;
SECTION: string;
SECTION_STATUS: string;
STOP: string;
};

export type HeatingClimateControlTransceiverDatapoint = {
ACTIVE_PROFILE: string;
ACTUAL_TEMPERATURE: string;
ACTUAL_TEMPERATURE_STATUS: string;
BOOST_MODE: string;
BOOST_TIME: string;
CONTROL_DIFFERENTIAL_TEMPERATURE: string;
CONTROL_MODE: string;
DURATION_UNIT: string;
DURATION_VALUE: string;
FROST_PROTECTION: string;
HEATING_COOLING: string;
HUMIDITY?: string;
HUMIDITY_STATUS?: string;
PARTY_MODE: string;
PARTY_SET_POINT_TEMPERATURE: string;
PARTY_TIME_END: string;
PARTY_TIME_START: string;
QUICK_VETO_TIME: string;
SET_POINT_MODE: string;
SET_POINT_TEMPERATURE: string;
SWITCH_POINT_OCCURED: string;
WINDOW_STATE: string;
LEVEL?: string;
LEVEL_STATUS?: string;
};

export type FloorClimateControlTransceiverDatapoint = {
DEW_POINT_ALARM: string;
EMERGENCY_OPERATION: string;
EXTERNAL_CLOCK: string;
FROST_PROTECTION: string;
HUMIDITY_LIMITER: string;
LEVEL: string;
LEVEL_STATUS: string;
VALVE_STATE: string;
};

interface BaseChannel {
id: number;
name: string;
address: string;
interfaceName: string;
}

export interface SwitchVirtualReceiverChannel extends BaseChannel {
type: ChannelType.SWITCH_VIRTUAL_RECEIVER;
datapoints: SwitchVirtualReceiverDatapoint;
}

export interface BlindVirtualReceiverChannel extends BaseChannel {
type: ChannelType.BLIND_VIRTUAL_RECEIVER;
datapoints: BlindVirtualReceiverDatapoint;
}

export interface HeatingClimateControlTransceiverChannel extends BaseChannel {
type: ChannelType.HEATING_CLIMATECONTROL_TRANSCEIVER;
datapoints: HeatingClimateControlTransceiverDatapoint;
}

export interface FloorClimateControlTransceiverChannel extends BaseChannel {
type: ChannelType.CLIMATECONTROL_FLOOR_TRANSCEIVER;
datapoints: FloorClimateControlTransceiverDatapoint
}

export type Channel = SwitchVirtualReceiverChannel | BlindVirtualReceiverChannel | HeatingClimateControlTransceiverChannel | FloorClimateControlTransceiverChannel;
import { Channel, ChannelType } from 'src/types/types';

interface Room {
name: string;
Expand Down
106 changes: 106 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
export enum ChannelType {
SWITCH_VIRTUAL_RECEIVER = "SWITCH_VIRTUAL_RECEIVER",
BLIND_VIRTUAL_RECEIVER = "BLIND_VIRTUAL_RECEIVER",
HEATING_CLIMATECONTROL_TRANSCEIVER = "HEATING_CLIMATECONTROL_TRANSCEIVER",
CLIMATECONTROL_FLOOR_TRANSCEIVER = "CLIMATECONTROL_FLOOR_TRANSCEIVER",
RAIN_DETECTION_TRANSMITTER = "RAIN_DETECTION_TRANSMITTER"
}

export type SwitchVirtualReceiverDatapoint = {
COMBINED_PARAMETER: string;
ON_TIME: string;
PROCESS: string;
SECTION: string;
SECTION_STATUS: string;
STATE: string;
};

export type BlindVirtualReceiverDatapoint = {
ACTIVITY_STATE: string;
COMBINED_PARAMETER: string;
LEVEL: string;
LEVEL_2: string;
LEVEL_2_STATUS: string;
LEVEL_STATUS: string;
PROCESS: string;
SECTION: string;
SECTION_STATUS: string;
STOP: string;
};

export type HeatingClimateControlTransceiverDatapoint = {
ACTIVE_PROFILE: string;
ACTUAL_TEMPERATURE: string;
ACTUAL_TEMPERATURE_STATUS: string;
BOOST_MODE: string;
BOOST_TIME: string;
CONTROL_DIFFERENTIAL_TEMPERATURE: string;
CONTROL_MODE: string;
DURATION_UNIT: string;
DURATION_VALUE: string;
FROST_PROTECTION: string;
HEATING_COOLING: string;
HUMIDITY?: string;
HUMIDITY_STATUS?: string;
PARTY_MODE: string;
PARTY_SET_POINT_TEMPERATURE: string;
PARTY_TIME_END: string;
PARTY_TIME_START: string;
QUICK_VETO_TIME: string;
SET_POINT_MODE: string;
SET_POINT_TEMPERATURE: string;
SWITCH_POINT_OCCURED: string;
WINDOW_STATE: string;
LEVEL?: string;
LEVEL_STATUS?: string;
};

export type FloorClimateControlTransceiverDatapoint = {
DEW_POINT_ALARM: string;
EMERGENCY_OPERATION: string;
EXTERNAL_CLOCK: string;
FROST_PROTECTION: string;
HUMIDITY_LIMITER: string;
LEVEL: string;
LEVEL_STATUS: string;
VALVE_STATE: string;
}

export type RainDesctionTransmitterDatapoint = {
RAINING: string;
HEATER_STATE: string;
}

interface BaseChannel {
id: number;
name: string;
address: string;
interfaceName: string;
}

export interface SwitchVirtualReceiverChannel extends BaseChannel {
type: ChannelType.SWITCH_VIRTUAL_RECEIVER;
datapoints: SwitchVirtualReceiverDatapoint;
}

export interface BlindVirtualReceiverChannel extends BaseChannel {
type: ChannelType.BLIND_VIRTUAL_RECEIVER;
datapoints: BlindVirtualReceiverDatapoint;
}

export interface HeatingClimateControlTransceiverChannel extends BaseChannel {
type: ChannelType.HEATING_CLIMATECONTROL_TRANSCEIVER;
datapoints: HeatingClimateControlTransceiverDatapoint;
}

export interface FloorClimateControlTransceiverChannel extends BaseChannel {
type: ChannelType.CLIMATECONTROL_FLOOR_TRANSCEIVER;
datapoints: FloorClimateControlTransceiverDatapoint
}

export interface RainDesctionTransmitterChannel extends BaseChannel {
type: ChannelType.RAIN_DETECTION_TRANSMITTER;
datapoints: RainDesctionTransmitterDatapoint
}

export type Channel = SwitchVirtualReceiverChannel | BlindVirtualReceiverChannel | HeatingClimateControlTransceiverChannel | FloorClimateControlTransceiverChannel | RainDesctionTransmitterChannel;

0 comments on commit 36fe00f

Please sign in to comment.