Merge pull request #136 from rjwats/ui-use-enums
prefer enums over named consts in UI for better static analysis
This commit is contained in:
commit
ddbb84454f
@ -1,7 +1,5 @@
|
||||
import { APSettings } from "./types";
|
||||
import { APSettings, ApProvisionMode } from "./types";
|
||||
|
||||
export const AP_MODE_ALWAYS = 0;
|
||||
export const AP_MODE_DISCONNECTED = 1;
|
||||
export const AP_NEVER = 2;
|
||||
|
||||
export const isAPEnabled = ({ provision_mode }: APSettings) => provision_mode === AP_MODE_ALWAYS || provision_mode === AP_MODE_DISCONNECTED;
|
||||
export const isAPEnabled = ({ provision_mode }: APSettings) => {
|
||||
return provision_mode === ApProvisionMode.AP_MODE_ALWAYS || provision_mode === ApProvisionMode.AP_MODE_DISCONNECTED;
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import SaveIcon from '@material-ui/icons/Save';
|
||||
|
||||
import {PasswordValidator, RestFormProps, FormActions, FormButton} from '../components';
|
||||
|
||||
import { isAPEnabled, AP_MODE_ALWAYS, AP_MODE_DISCONNECTED, AP_NEVER } from './APModes';
|
||||
import { APSettings } from './types';
|
||||
import { isAPEnabled } from './APModes';
|
||||
import { APSettings, ApProvisionMode } from './types';
|
||||
|
||||
type APSettingsFormProps = RestFormProps<APSettings>;
|
||||
|
||||
@ -24,9 +24,9 @@ class APSettingsForm extends React.Component<APSettingsFormProps> {
|
||||
variant="outlined"
|
||||
onChange={handleValueChange('provision_mode')}
|
||||
margin="normal">
|
||||
<MenuItem value={AP_MODE_ALWAYS}>Always</MenuItem>
|
||||
<MenuItem value={AP_MODE_DISCONNECTED}>When WiFi Disconnected</MenuItem>
|
||||
<MenuItem value={AP_NEVER}>Never</MenuItem>
|
||||
<MenuItem value={ApProvisionMode.AP_MODE_ALWAYS}>Always</MenuItem>
|
||||
<MenuItem value={ApProvisionMode.AP_MODE_DISCONNECTED}>When WiFi Disconnected</MenuItem>
|
||||
<MenuItem value={ApProvisionMode.AP_NEVER}>Never</MenuItem>
|
||||
</SelectValidator>
|
||||
{
|
||||
isAPEnabled(data) &&
|
||||
|
@ -1,3 +1,9 @@
|
||||
export enum ApProvisionMode {
|
||||
AP_MODE_ALWAYS = 0,
|
||||
AP_MODE_DISCONNECTED = 1,
|
||||
AP_NEVER = 2
|
||||
}
|
||||
|
||||
export interface APStatus {
|
||||
active: boolean;
|
||||
ip_address: string;
|
||||
@ -6,7 +12,7 @@ export interface APStatus {
|
||||
}
|
||||
|
||||
export interface APSettings {
|
||||
provision_mode: number;
|
||||
provision_mode: ApProvisionMode;
|
||||
ssid: string;
|
||||
password: string;
|
||||
}
|
||||
|
@ -1,16 +1,13 @@
|
||||
import { Theme } from "@material-ui/core";
|
||||
import { NTPStatus } from "./types";
|
||||
import { NTPStatus, NTPSyncStatus } from "./types";
|
||||
|
||||
export const NTP_INACTIVE = 0;
|
||||
export const NTP_ACTIVE = 1;
|
||||
|
||||
export const isNtpActive = ({ status }: NTPStatus) => status === NTP_ACTIVE;
|
||||
export const isNtpActive = ({ status }: NTPStatus) => status === NTPSyncStatus.NTP_ACTIVE;
|
||||
|
||||
export const ntpStatusHighlight = ({ status }: NTPStatus, theme: Theme) => {
|
||||
switch (status) {
|
||||
case NTP_INACTIVE:
|
||||
case NTPSyncStatus.NTP_INACTIVE:
|
||||
return theme.palette.info.main;
|
||||
case NTP_ACTIVE:
|
||||
case NTPSyncStatus.NTP_ACTIVE:
|
||||
return theme.palette.success.main;
|
||||
default:
|
||||
return theme.palette.error.main;
|
||||
@ -19,9 +16,9 @@ export const ntpStatusHighlight = ({ status }: NTPStatus, theme: Theme) => {
|
||||
|
||||
export const ntpStatus = ({ status }: NTPStatus) => {
|
||||
switch (status) {
|
||||
case NTP_INACTIVE:
|
||||
case NTPSyncStatus.NTP_INACTIVE:
|
||||
return "Inactive";
|
||||
case NTP_ACTIVE:
|
||||
case NTPSyncStatus.NTP_ACTIVE:
|
||||
return "Active";
|
||||
default:
|
||||
return "Unknown";
|
||||
|
@ -1,5 +1,10 @@
|
||||
export enum NTPSyncStatus {
|
||||
NTP_INACTIVE = 0,
|
||||
NTP_ACTIVE = 1
|
||||
}
|
||||
|
||||
export interface NTPStatus {
|
||||
status: number;
|
||||
status: NTPSyncStatus;
|
||||
time_utc: string;
|
||||
time_local: string;
|
||||
server: string;
|
||||
|
@ -1,26 +1,19 @@
|
||||
import { WiFiNetwork } from "./types";
|
||||
import { WiFiNetwork, WiFiEncryptionType } from "./types";
|
||||
|
||||
export const WIFI_AUTH_OPEN = 0;
|
||||
export const WIFI_AUTH_WEP = 1;
|
||||
export const WIFI_AUTH_WEP_PSK = 2;
|
||||
export const WIFI_AUTH_WEP2_PSK = 3;
|
||||
export const WIFI_AUTH_WPA_WPA2_PSK = 4;
|
||||
export const WIFI_AUTH_WPA2_ENTERPRISE = 5;
|
||||
|
||||
export const isNetworkOpen = ({ encryption_type }: WiFiNetwork) => encryption_type === WIFI_AUTH_OPEN;
|
||||
export const isNetworkOpen = ({ encryption_type }: WiFiNetwork) => encryption_type === WiFiEncryptionType.WIFI_AUTH_OPEN;
|
||||
|
||||
export const networkSecurityMode = ({ encryption_type }: WiFiNetwork) => {
|
||||
switch (encryption_type) {
|
||||
case WIFI_AUTH_WEP:
|
||||
case WIFI_AUTH_WEP_PSK:
|
||||
case WiFiEncryptionType.WIFI_AUTH_WEP:
|
||||
case WiFiEncryptionType.WIFI_AUTH_WEP_PSK:
|
||||
return "WEP";
|
||||
case WIFI_AUTH_WEP2_PSK:
|
||||
case WiFiEncryptionType.WIFI_AUTH_WEP2_PSK:
|
||||
return "WEP2";
|
||||
case WIFI_AUTH_WPA_WPA2_PSK:
|
||||
case WiFiEncryptionType.WIFI_AUTH_WPA_WPA2_PSK:
|
||||
return "WPA/WEP2";
|
||||
case WIFI_AUTH_WPA2_ENTERPRISE:
|
||||
case WiFiEncryptionType.WIFI_AUTH_WPA2_ENTERPRISE:
|
||||
return "WEP2 Enterprise";
|
||||
case WIFI_AUTH_OPEN:
|
||||
case WiFiEncryptionType.WIFI_AUTH_OPEN:
|
||||
return "None";
|
||||
default:
|
||||
return "Unknown";
|
||||
|
@ -1,24 +1,17 @@
|
||||
import { Theme } from '@material-ui/core';
|
||||
import { WiFiStatus } from './types';
|
||||
import { WiFiStatus, WiFiConnectionStatus } from './types';
|
||||
|
||||
export const WIFI_STATUS_IDLE = 0;
|
||||
export const WIFI_STATUS_NO_SSID_AVAIL = 1;
|
||||
export const WIFI_STATUS_CONNECTED = 3;
|
||||
export const WIFI_STATUS_CONNECT_FAILED = 4;
|
||||
export const WIFI_STATUS_CONNECTION_LOST = 5;
|
||||
export const WIFI_STATUS_DISCONNECTED = 6;
|
||||
|
||||
export const isConnected = ({ status }: WiFiStatus) => status === WIFI_STATUS_CONNECTED;
|
||||
export const isConnected = ({ status }: WiFiStatus) => status === WiFiConnectionStatus.WIFI_STATUS_CONNECTED;
|
||||
|
||||
export const wifiStatusHighlight = ({ status }: WiFiStatus, theme: Theme) => {
|
||||
switch (status) {
|
||||
case WIFI_STATUS_IDLE:
|
||||
case WIFI_STATUS_DISCONNECTED:
|
||||
case WiFiConnectionStatus.WIFI_STATUS_IDLE:
|
||||
case WiFiConnectionStatus.WIFI_STATUS_DISCONNECTED:
|
||||
return theme.palette.info.main;
|
||||
case WIFI_STATUS_CONNECTED:
|
||||
case WiFiConnectionStatus.WIFI_STATUS_CONNECTED:
|
||||
return theme.palette.success.main;
|
||||
case WIFI_STATUS_CONNECT_FAILED:
|
||||
case WIFI_STATUS_CONNECTION_LOST:
|
||||
case WiFiConnectionStatus.WIFI_STATUS_CONNECT_FAILED:
|
||||
case WiFiConnectionStatus.WIFI_STATUS_CONNECTION_LOST:
|
||||
return theme.palette.error.main;
|
||||
default:
|
||||
return theme.palette.warning.main;
|
||||
@ -27,17 +20,17 @@ export const wifiStatusHighlight = ({ status }: WiFiStatus, theme: Theme) => {
|
||||
|
||||
export const wifiStatus = ({ status }: WiFiStatus) => {
|
||||
switch (status) {
|
||||
case WIFI_STATUS_IDLE:
|
||||
case WiFiConnectionStatus.WIFI_STATUS_IDLE:
|
||||
return "Idle";
|
||||
case WIFI_STATUS_NO_SSID_AVAIL:
|
||||
case WiFiConnectionStatus.WIFI_STATUS_NO_SSID_AVAIL:
|
||||
return "No SSID Available";
|
||||
case WIFI_STATUS_CONNECTED:
|
||||
case WiFiConnectionStatus.WIFI_STATUS_CONNECTED:
|
||||
return "Connected";
|
||||
case WIFI_STATUS_CONNECT_FAILED:
|
||||
case WiFiConnectionStatus.WIFI_STATUS_CONNECT_FAILED:
|
||||
return "Connection Failed";
|
||||
case WIFI_STATUS_CONNECTION_LOST:
|
||||
case WiFiConnectionStatus.WIFI_STATUS_CONNECTION_LOST:
|
||||
return "Connection Lost";
|
||||
case WIFI_STATUS_DISCONNECTED:
|
||||
case WiFiConnectionStatus.WIFI_STATUS_DISCONNECTED:
|
||||
return "Disconnected";
|
||||
default:
|
||||
return "Unknown";
|
||||
|
@ -1,5 +1,23 @@
|
||||
export enum WiFiConnectionStatus {
|
||||
WIFI_STATUS_IDLE = 0,
|
||||
WIFI_STATUS_NO_SSID_AVAIL = 1,
|
||||
WIFI_STATUS_CONNECTED = 3,
|
||||
WIFI_STATUS_CONNECT_FAILED = 4,
|
||||
WIFI_STATUS_CONNECTION_LOST = 5,
|
||||
WIFI_STATUS_DISCONNECTED = 6
|
||||
}
|
||||
|
||||
export enum WiFiEncryptionType {
|
||||
WIFI_AUTH_OPEN = 0,
|
||||
WIFI_AUTH_WEP = 1,
|
||||
WIFI_AUTH_WEP_PSK = 2,
|
||||
WIFI_AUTH_WEP2_PSK = 3,
|
||||
WIFI_AUTH_WPA_WPA2_PSK = 4,
|
||||
WIFI_AUTH_WPA2_ENTERPRISE = 5
|
||||
}
|
||||
|
||||
export interface WiFiStatus {
|
||||
status: number;
|
||||
status: WiFiConnectionStatus;
|
||||
local_ip: string;
|
||||
mac_address: string;
|
||||
rssi: number;
|
||||
@ -33,5 +51,5 @@ export interface WiFiNetwork {
|
||||
ssid: string;
|
||||
bssid: string;
|
||||
channel: number;
|
||||
encryption_type: number;
|
||||
encryption_type: WiFiEncryptionType;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user