From 18838eae12aa735b3d70b4af313c9f9392d052fa Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Mon, 19 Aug 2024 14:23:27 -0700 Subject: [PATCH] fix: Use available_hvac_mode_settings over bool props --- .storybook/seed-fake.js | 16 ------------- .../DeviceDetails/ThermostatDeviceDetails.tsx | 10 ++++---- .../seam/thermostats/temperature-bounds.ts | 23 ------------------- src/lib/seam/thermostats/thermostat-device.ts | 4 ---- .../seam/thermostats/use-cool-thermostat.ts | 2 -- .../thermostats/use-heat-cool-thermostat.ts | 2 -- .../seam/thermostats/use-heat-thermostat.ts | 2 -- .../thermostats/use-set-thermostat-off.ts | 2 -- .../ui/ClimateSettingForm/set-point-bounds.ts | 6 ++--- 9 files changed, 8 insertions(+), 59 deletions(-) diff --git a/.storybook/seed-fake.js b/.storybook/seed-fake.js index 9204036fb..7f7e4807a 100644 --- a/.storybook/seed-fake.js +++ b/.storybook/seed-fake.js @@ -378,8 +378,6 @@ export const seedFake = (db) => { online: true, is_cooling: false, is_heating: false, - is_heating_available: true, - is_cooling_available: true, manufacturer: 'ecobee', is_fan_running: false, model: { @@ -397,8 +395,6 @@ export const seedFake = (db) => { current_climate_setting: { hvac_mode_setting: 'heat_cool', manual_override_allowed: false, - automatic_cooling_enabled: true, - automatic_heating_enabled: true, cooling_set_point_fahrenheit: 75, cooling_set_point_celsius: 23.8, heating_set_point_fahrenheit: 65, @@ -407,8 +403,6 @@ export const seedFake = (db) => { default_climate_setting: { hvac_mode_setting: 'heat_cool', manual_override_allowed: false, - automatic_cooling_enabled: true, - automatic_heating_enabled: true, cooling_set_point_fahrenheit: 75, cooling_set_point_celsius: 23.8, heating_set_point_fahrenheit: 65, @@ -464,16 +458,12 @@ export const seedFake = (db) => { current_climate_setting: { hvac_mode_setting: 'heat', manual_override_allowed: false, - automatic_cooling_enabled: false, - automatic_heating_enabled: true, heating_set_point_celsius: 20, heating_set_point_fahrenheit: 68, }, available_hvac_mode_settings: ['off', 'cool', 'heat', 'heat_cool'], can_enable_automatic_cooling: true, can_enable_automatic_heating: true, - is_cooling_available: true, - is_heating_available: true, max_cooling_set_point_celsius: 33.333333333333336, max_heating_set_point_celsius: 26.11111111111111, min_cooling_set_point_celsius: 18.333333333333336, @@ -571,8 +561,6 @@ export const seedFake = (db) => { schedule_ends_at: '2024-08-01T00:00:00.000Z', schedule_type: 'time_bound', manual_override_allowed: true, - automatic_heating_enabled: false, - automatic_cooling_enabled: true, hvac_mode_setting: 'cool', cooling_set_point_fahrenheit: 70, cooling_set_point_celsius: 21, @@ -587,8 +575,6 @@ export const seedFake = (db) => { schedule_ends_at: '2024-07-14T00:00:00.000Z', schedule_type: 'time_bound', manual_override_allowed: true, - automatic_heating_enabled: true, - automatic_cooling_enabled: true, hvac_mode_setting: 'heat_cool', heating_set_point_fahrenheit: 65, heating_set_point_celsius: 18, @@ -605,8 +591,6 @@ export const seedFake = (db) => { schedule_ends_at: '2027-08-14T00:00:00.000Z', schedule_type: 'time_bound', manual_override_allowed: true, - automatic_heating_enabled: false, - automatic_cooling_enabled: true, hvac_mode_setting: 'cool', cooling_set_point_fahrenheit: 72, cooling_set_point_celsius: 22.2222, diff --git a/src/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.tsx b/src/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.tsx index 139a3eca8..8d06b5b5a 100644 --- a/src/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.tsx +++ b/src/lib/seam/components/DeviceDetails/ThermostatDeviceDetails.tsx @@ -8,7 +8,6 @@ import { NestedClimateSettingScheduleTable } from 'lib/seam/components/ClimateSe import type { NestedSpecificDeviceDetailsProps } from 'lib/seam/components/DeviceDetails/DeviceDetails.js' import { DeviceInfo } from 'lib/seam/components/DeviceDetails/DeviceInfo.js' import { useClimateSettingSchedules } from 'lib/seam/thermostats/climate-setting-schedules/use-climate-setting-schedules.js' -import { getSupportedThermostatModes } from 'lib/seam/thermostats/temperature-bounds.js' import type { HvacModeSetting, ThermostatDevice, @@ -252,12 +251,13 @@ function ClimateSettingRow({ const deviceCoolValue = device.properties.current_climate_setting.cooling_set_point_fahrenheit - const supportedModes = getSupportedThermostatModes(device) + const availableHvacModes = device.properties.available_hvac_mode_settings const [showSuccess, setShowSuccess] = useState(false) const [mode, setMode] = useState( - (supportedModes.includes('heat_cool') ? 'heat_cool' : supportedModes[0]) ?? - 'off' + (availableHvacModes.includes('heat_cool') + ? 'heat_cool' + : availableHvacModes[0]) ?? 'off' ) const [heatValue, setHeatValue] = useState( @@ -413,7 +413,7 @@ function ClimateSettingRow({ diff --git a/src/lib/seam/thermostats/temperature-bounds.ts b/src/lib/seam/thermostats/temperature-bounds.ts index ec4a2258b..5107a0261 100644 --- a/src/lib/seam/thermostats/temperature-bounds.ts +++ b/src/lib/seam/thermostats/temperature-bounds.ts @@ -1,6 +1,5 @@ import type { HvacModeSetting, - ThermostatDevice, } from 'lib/seam/thermostats/thermostat-device.js' export interface ControlBounds { @@ -54,25 +53,3 @@ export const getTemperatureBounds = ( heat: getHeatBounds(controlBounds), cool: getCoolBounds(controlBounds), }) - -export const getSupportedThermostatModes = ( - device: ThermostatDevice -): HvacModeSetting[] => { - const allModes: HvacModeSetting[] = ['heat', 'cool', 'heat_cool', 'off'] - - return allModes.filter((mode) => { - switch (mode) { - case 'cool': - return device.properties.is_cooling_available ?? false - case 'heat': - return device.properties.is_heating_available ?? false - case 'heat_cool': - return ( - (device.properties.is_heating_available ?? false) && - (device.properties.is_cooling_available ?? false) - ) - default: - return true - } - }) -} diff --git a/src/lib/seam/thermostats/thermostat-device.ts b/src/lib/seam/thermostats/thermostat-device.ts index 27487efd4..e76175876 100644 --- a/src/lib/seam/thermostats/thermostat-device.ts +++ b/src/lib/seam/thermostats/thermostat-device.ts @@ -10,8 +10,6 @@ export type ThermostatDevice = Omit & { | 'is_heating' | 'is_cooling' | 'is_fan_running' - | 'is_cooling_available' - | 'is_heating_available' | 'available_hvac_mode_settings' | 'fan_mode_setting' | 'current_climate_setting' @@ -28,8 +26,6 @@ export type HvacModeSetting = // UPSTREAM: ClimateSetting missing in @seamapi/types. export interface ClimateSetting { - automatic_heating_enabled?: boolean - automatic_cooling_enabled?: boolean hvac_mode_setting?: HvacModeSetting cooling_set_point_celsius?: number heating_set_point_celsius?: number diff --git a/src/lib/seam/thermostats/use-cool-thermostat.ts b/src/lib/seam/thermostats/use-cool-thermostat.ts index d5adfac3c..6c196d5d6 100644 --- a/src/lib/seam/thermostats/use-cool-thermostat.ts +++ b/src/lib/seam/thermostats/use-cool-thermostat.ts @@ -100,8 +100,6 @@ const getUpdatedDevice = ( current_climate_setting: { ...properties.current_climate_setting, hvac_mode_setting: 'cool', - automatic_heating_enabled: false, - automatic_cooling_enabled: true, heating_set_point_celsius: undefined, heating_set_point_fahrenheit: undefined, cooling_set_point_celsius: getCoolingSetPointCelsius( diff --git a/src/lib/seam/thermostats/use-heat-cool-thermostat.ts b/src/lib/seam/thermostats/use-heat-cool-thermostat.ts index 22fdc87ed..2c9cb6591 100644 --- a/src/lib/seam/thermostats/use-heat-cool-thermostat.ts +++ b/src/lib/seam/thermostats/use-heat-cool-thermostat.ts @@ -106,8 +106,6 @@ const getUpdatedDevice = ( current_climate_setting: { ...properties.current_climate_setting, hvac_mode_setting: 'heat_cool', - automatic_heating_enabled: true, - automatic_cooling_enabled: true, heating_set_point_celsius: getHeatingSetPointCelsius( variables, device diff --git a/src/lib/seam/thermostats/use-heat-thermostat.ts b/src/lib/seam/thermostats/use-heat-thermostat.ts index b3ce3c3a0..8e1fccef9 100644 --- a/src/lib/seam/thermostats/use-heat-thermostat.ts +++ b/src/lib/seam/thermostats/use-heat-thermostat.ts @@ -100,8 +100,6 @@ const getUpdatedDevice = ( current_climate_setting: { ...properties.current_climate_setting, hvac_mode_setting: 'heat', - automatic_heating_enabled: true, - automatic_cooling_enabled: false, cooling_set_point_celsius: undefined, cooling_set_point_fahrenheit: undefined, heating_set_point_celsius: getHeatingSetPointCelsius( diff --git a/src/lib/seam/thermostats/use-set-thermostat-off.ts b/src/lib/seam/thermostats/use-set-thermostat-off.ts index 5cf6b148a..7a36f7d9b 100644 --- a/src/lib/seam/thermostats/use-set-thermostat-off.ts +++ b/src/lib/seam/thermostats/use-set-thermostat-off.ts @@ -92,8 +92,6 @@ const getUpdatedDevice = (device: Device): Device => { is_heating: false, current_climate_setting: { ...properties.current_climate_setting, - automatic_cooling_enabled: false, - automatic_heating_enabled: false, hvac_mode_setting: 'off', heating_set_point_celsius: undefined, heating_set_point_fahrenheit: undefined, diff --git a/src/lib/ui/ClimateSettingForm/set-point-bounds.ts b/src/lib/ui/ClimateSettingForm/set-point-bounds.ts index b8a7cd529..77bc0f6ce 100644 --- a/src/lib/ui/ClimateSettingForm/set-point-bounds.ts +++ b/src/lib/ui/ClimateSettingForm/set-point-bounds.ts @@ -13,17 +13,17 @@ export const getSetPointBounds = (device: ThermostatDevice): SetPointBounds => { const setPointBounds: SetPointBounds = {} - if (properties.is_cooling_available) { + if (properties.available_hvac_mode_settings.includes('cool')) { setPointBounds.minCool = properties.min_cooling_set_point_fahrenheit setPointBounds.maxCool = properties.max_cooling_set_point_fahrenheit } - if (properties.is_heating_available) { + if (properties.available_hvac_mode_settings.includes('heat')) { setPointBounds.minHeat = properties.min_heating_set_point_fahrenheit setPointBounds.maxHeat = properties.max_heating_set_point_fahrenheit } - if (properties.is_cooling_available && properties.is_heating_available) { + if (properties.available_hvac_mode_settings.includes('heat_cool')) { setPointBounds.delta = properties.min_heating_cooling_delta_fahrenheit }