Skip to content

Commit 397b0b3

Browse files
committed
Don't expose "cooling/heating allowed" settings for legacy EDA units
Fixes #105
1 parent eb0021b commit 397b0b3

File tree

3 files changed

+44
-22
lines changed

3 files changed

+44
-22
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Upgrade `mqtt` to get rid of `async-mqtt` (https://github.com/Jalle19/eda-modbus-bridge/issues/95)
66
* Remove flaky support for "PRO" unit naming scheme
77
* Add rudimentary way of differentiating between different automation types
8+
* Disable "heating/cooling allowed" on legacy EDA units, fixes crash (https://github.com/Jalle19/eda-modbus-bridge/issues/105)
89

910
## 2.7.1
1011

app/homeassistant.mjs

+24-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
TOPIC_PREFIX_SETTINGS,
99
} from './mqtt.mjs'
1010
import { createLogger } from './logger.mjs'
11-
import { AVAILABLE_ALARMS, createModelNameString } from './enervent.mjs'
11+
import { AUTOMATION_TYPE_LEGACY_EDA, AVAILABLE_ALARMS, createModelNameString } from './enervent.mjs'
1212

1313
const logger = createLogger('homeassistant')
1414

@@ -17,6 +17,7 @@ export const configureMqttDiscovery = async (modbusClient, mqttClient) => {
1717
// names, so it must match [a-zA-Z0-9_-].
1818
const modbusDeviceInformation = await getDeviceInformation(modbusClient)
1919
const softwareVersion = modbusDeviceInformation.softwareVersion
20+
const automationType = modbusDeviceInformation.automationType
2021
const modelName = createModelNameString(modbusDeviceInformation)
2122
const deviceIdentifier = createDeviceIdentifierString(modbusDeviceInformation)
2223

@@ -223,30 +224,46 @@ export const configureMqttDiscovery = async (modbusClient, mqttClient) => {
223224
),
224225
'eco': createModeSwitchConfiguration(configurationBase, 'eco', 'Eco'),
225226
// Settings switches
226-
'coolingAllowed': createSettingSwitchConfiguration(configurationBase, 'coolingAllowed', 'Cooling allowed'),
227-
'heatingAllowed': createSettingSwitchConfiguration(configurationBase, 'heatingAllowed', 'Heating allowed'),
228227
'awayCoolingAllowed': createSettingSwitchConfiguration(
229228
configurationBase,
230229
'awayCoolingAllowed',
231-
'Cooling allowed (away mode)'
230+
'Cooling allowed (away mode)',
231+
// Not supported by some units
232+
{ 'enabled_by_default': automationType !== AUTOMATION_TYPE_LEGACY_EDA }
232233
),
233234
'awayHeatingAllowed': createSettingSwitchConfiguration(
234235
configurationBase,
235236
'awayHeatingAllowed',
236-
'Heating allowed (away mode)'
237+
'Heating allowed (away mode)',
238+
// Not supported by some units
239+
{ 'enabled_by_default': automationType !== AUTOMATION_TYPE_LEGACY_EDA }
237240
),
238241
'longAwayCoolingAllowed': createSettingSwitchConfiguration(
239242
configurationBase,
240243
'longAwayCoolingAllowed',
241-
'Cooling allowed (long away mode)'
244+
'Cooling allowed (long away mode)',
245+
// Not supported by some units
246+
{ 'enabled_by_default': automationType !== AUTOMATION_TYPE_LEGACY_EDA }
242247
),
243248
'longAwayHeatingAllowed': createSettingSwitchConfiguration(
244249
configurationBase,
245250
'longAwayHeatingAllowed',
246-
'Heating allowed (long away mode)'
251+
'Heating allowed (long away mode)',
252+
// Not supported by some units
253+
{ 'enabled_by_default': automationType !== AUTOMATION_TYPE_LEGACY_EDA }
247254
),
248255
}
249256

257+
// Optional switches depending on automation type
258+
if (automationType !== AUTOMATION_TYPE_LEGACY_EDA) {
259+
switchConfigurationMap = {
260+
...switchConfigurationMap,
261+
// Settings switches
262+
'coolingAllowed': createSettingSwitchConfiguration(configurationBase, 'coolingAllowed', 'Cooling allowed'),
263+
'heatingAllowed': createSettingSwitchConfiguration(configurationBase, 'heatingAllowed', 'Heating allowed'),
264+
}
265+
}
266+
250267
// Binary sensors for alarms
251268
let binarySensorConfigurationMap = {}
252269

app/modbus.mjs

+19-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Mutex } from 'async-mutex'
22
import { createLogger } from './logger.mjs'
33
import {
4+
AUTOMATION_TYPE_LEGACY_EDA,
45
AVAILABLE_ALARMS,
56
AVAILABLE_FLAGS,
67
AVAILABLE_SETTINGS,
@@ -178,22 +179,25 @@ export const getSettings = async (modbusClient) => {
178179
'temperatureTarget': parseTemperature(result.data[0]),
179180
}
180181

181-
// Heating/cooling/heat recovery enabled in normal/away/long away modes. Note that the register order is swapped
182-
// when querying register 18-21 compared to 52-55.
183-
result = await mutex.runExclusive(async () => tryReadCoils(modbusClient, 52, 3))
184-
settings = {
185-
...settings,
186-
'coolingAllowed': result.data[0],
187-
'heatingAllowed': result.data[2],
188-
}
182+
// Heating/cooling/heat recovery enabled in normal/away/long away modes (not available on some devices).
183+
// Note that the register order is swapped when querying register 18-21 compared to 52-55.
184+
const deviceInformation = await getDeviceInformation(modbusClient)
185+
if (deviceInformation.automationType !== AUTOMATION_TYPE_LEGACY_EDA) {
186+
result = await mutex.runExclusive(async () => tryReadCoils(modbusClient, 52, 3))
187+
settings = {
188+
...settings,
189+
'coolingAllowed': result.data[0],
190+
'heatingAllowed': result.data[2],
191+
}
189192

190-
result = await mutex.runExclusive(async () => tryReadCoils(modbusClient, 18, 4))
191-
settings = {
192-
...settings,
193-
'awayCoolingAllowed': result.data[1],
194-
'awayHeatingAllowed': result.data[0],
195-
'longAwayCoolingAllowed': result.data[3],
196-
'longAwayHeatingAllowed': result.data[2],
193+
result = await mutex.runExclusive(async () => tryReadCoils(modbusClient, 18, 4))
194+
settings = {
195+
...settings,
196+
'awayCoolingAllowed': result.data[1],
197+
'awayHeatingAllowed': result.data[0],
198+
'longAwayCoolingAllowed': result.data[3],
199+
'longAwayHeatingAllowed': result.data[2],
200+
}
197201
}
198202

199203
return settings

0 commit comments

Comments
 (0)