@@ -2,7 +2,7 @@ import {describe, expect, it, vi} from "vitest";
22import { findByDevice } from "../src/index" ;
33import { boschThermostatExtend } from "../src/lib/bosch" ;
44import { repInterval } from "../src/lib/constants" ;
5- import type { DefinitionExposesFunction } from "../src/lib/types" ;
5+ import type { DefinitionExposesFunction , KeyValueAny } from "../src/lib/types" ;
66import { mockDevice , reportingItem } from "./utils" ;
77
88describe ( "Bosch thermostats" , ( ) => {
@@ -76,3 +76,52 @@ describe("Bosch thermostat relayState extension", () => {
7676 expect ( device . getEndpoint ( 1 ) . configureReporting ) . not . toHaveBeenCalled ( ) ;
7777 } ) ;
7878} ) ;
79+
80+ describe ( "Bosch Room thermostat II 230V Home Assistant climate modes" , ( ) => {
81+ const getDefinition = ( ) =>
82+ findByDevice (
83+ mockDevice ( {
84+ modelID : "RBSH-RTH0-ZB-EU" ,
85+ manufacturerName : "BOSCH" ,
86+ endpoints : [ { ID : 1 , inputClusters : [ "hvacThermostat" ] } ] ,
87+ } ) ,
88+ ) ;
89+
90+ const buildPayload = async ( options = { } ) => {
91+ const definition = await getDefinition ( ) ;
92+ const payload : KeyValueAny = {
93+ mode_command_topic : "zigbee2mqtt/bad_thermostat/set/system_mode" ,
94+ } ;
95+
96+ definition . meta ?. overrideHaDiscoveryPayload ?.( payload , options ) ;
97+
98+ return { definition, payload} ;
99+ } ;
100+
101+ it ( "defaults to heat-only Home Assistant climate discovery" , async ( ) => {
102+ const { definition, payload} = await buildPayload ( ) ;
103+ const option = definition . options ?. find ( ( option ) => option . name === "homeassistant_climate_modes" ) ;
104+
105+ expect ( option ?. label ) . toBe ( "Home Assistant climate modes" ) ;
106+ expect ( payload . mode_command_topic ) . toBe ( "zigbee2mqtt/bad_thermostat/set" ) ;
107+ expect ( payload . mode_command_template ) . toContain ( "{% set active_modes = ['heat'] %}" ) ;
108+ expect ( payload . mode_state_template ) . toContain ( "{% set fallback_mode = 'heat' %}" ) ;
109+ expect ( payload . modes ) . toStrictEqual ( [ "off" , "heat" , "auto" ] ) ;
110+ } ) ;
111+
112+ it ( "can expose cool-only Home Assistant climate discovery" , async ( ) => {
113+ const { payload} = await buildPayload ( { homeassistant_climate_modes : "cool" } ) ;
114+
115+ expect ( payload . mode_command_template ) . toContain ( "{% set active_modes = ['cool'] %}" ) ;
116+ expect ( payload . mode_state_template ) . toContain ( "{% set fallback_mode = 'cool' %}" ) ;
117+ expect ( payload . modes ) . toStrictEqual ( [ "off" , "cool" , "auto" ] ) ;
118+ } ) ;
119+
120+ it ( "can expose heat and cool Home Assistant climate discovery" , async ( ) => {
121+ const { payload} = await buildPayload ( { homeassistant_climate_modes : "heat_cool" } ) ;
122+
123+ expect ( payload . mode_command_template ) . toContain ( "{% set active_modes = ['heat','cool'] %}" ) ;
124+ expect ( payload . mode_state_template ) . toContain ( "{% set fallback_mode = 'heat' %}" ) ;
125+ expect ( payload . modes ) . toStrictEqual ( [ "off" , "heat" , "cool" , "auto" ] ) ;
126+ } ) ;
127+ } ) ;
0 commit comments