Skip to content

Commit a1c3a85

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

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
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

+13-4
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

@@ -208,7 +209,7 @@ export const configureMqttDiscovery = async (modbusClient, mqttClient) => {
208209
}
209210

210211
// Configurable switches
211-
const switchConfigurationMap = {
212+
let switchConfigurationMap = {
212213
// Mode switches
213214
'away': createModeSwitchConfiguration(configurationBase, 'away', 'Away'),
214215
'longAway': createModeSwitchConfiguration(configurationBase, 'longAway', 'Long away'),
@@ -223,8 +224,6 @@ 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',
@@ -247,6 +246,16 @@ export const configureMqttDiscovery = async (modbusClient, mqttClient) => {
247246
),
248247
}
249248

249+
// Optional switches depending on automation type
250+
if (automationType !== AUTOMATION_TYPE_LEGACY_EDA) {
251+
switchConfigurationMap = {
252+
...switchConfigurationMap,
253+
// Settings switches
254+
'coolingAllowed': createSettingSwitchConfiguration(configurationBase, 'coolingAllowed', 'Cooling allowed'),
255+
'heatingAllowed': createSettingSwitchConfiguration(configurationBase, 'heatingAllowed', 'Heating allowed'),
256+
}
257+
}
258+
250259
// Binary sensors for alarms
251260
let binarySensorConfigurationMap = {}
252261

app/modbus.mjs

+12-7
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,15 +179,19 @@ 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],
182+
// Heating/cooling/heat recovery enabled in normal mode (not available on some devices)
183+
const deviceInformation = await getDeviceInformation(modbusClient)
184+
if (deviceInformation.automationType !== AUTOMATION_TYPE_LEGACY_EDA) {
185+
result = await mutex.runExclusive(async () => tryReadCoils(modbusClient, 52, 3))
186+
settings = {
187+
...settings,
188+
'coolingAllowed': result.data[0],
189+
'heatingAllowed': result.data[2],
190+
}
188191
}
189192

193+
// Heating/cooling/heat recovery enabled in away/long away modes. Note that the register order is swapped
194+
// when querying register 18-21 compared to 52-55.
190195
result = await mutex.runExclusive(async () => tryReadCoils(modbusClient, 18, 4))
191196
settings = {
192197
...settings,

0 commit comments

Comments
 (0)