Skip to content

Commit

Permalink
fix: Use available_hvac_mode_settings over bool props
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Aug 19, 2024
1 parent 2390cf1 commit 18838ea
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 59 deletions.
16 changes: 0 additions & 16 deletions .storybook/seed-fake.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<HvacModeSetting>(
(supportedModes.includes('heat_cool') ? 'heat_cool' : supportedModes[0]) ??
'off'
(availableHvacModes.includes('heat_cool')
? 'heat_cool'
: availableHvacModes[0]) ?? 'off'
)

const [heatValue, setHeatValue] = useState(
Expand Down Expand Up @@ -413,7 +413,7 @@ function ClimateSettingRow({
<ClimateModeMenu
mode={mode}
onChange={setMode}
supportedModes={supportedModes}
supportedModes={availableHvacModes}
/>
</div>
</AccordionRow>
Expand Down
23 changes: 0 additions & 23 deletions src/lib/seam/thermostats/temperature-bounds.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {
HvacModeSetting,
ThermostatDevice,
} from 'lib/seam/thermostats/thermostat-device.js'

export interface ControlBounds {
Expand Down Expand Up @@ -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
}
})
}
4 changes: 0 additions & 4 deletions src/lib/seam/thermostats/thermostat-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export type ThermostatDevice = Omit<Device, 'properties'> & {
| 'is_heating'
| 'is_cooling'
| 'is_fan_running'
| 'is_cooling_available'
| 'is_heating_available'
| 'available_hvac_mode_settings'
| 'fan_mode_setting'
| 'current_climate_setting'
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/lib/seam/thermostats/use-cool-thermostat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions src/lib/seam/thermostats/use-heat-cool-thermostat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/lib/seam/thermostats/use-heat-thermostat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions src/lib/seam/thermostats/use-set-thermostat-off.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/ui/ClimateSettingForm/set-point-bounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 18838ea

Please sign in to comment.