Skip to content

Commit

Permalink
rework some mapping rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ai91 committed Sep 22, 2024
1 parent d82a75f commit bd8d467
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void castValue() {
}

@Test
void testConfig() throws JsonMappingException, JsonProcessingException {
void testMappingRules1() throws JsonMappingException, JsonProcessingException {

String jsonString = TestUtil.readResource("/valuemapstest/device.json");

Expand Down Expand Up @@ -77,4 +77,46 @@ Optional<Device> findDevice(String deviceId) {
assertEquals(0, deviceState.capabilities.size());
}

@Test
void testMappingRules2() throws JsonMappingException, JsonProcessingException {

String jsonString = TestUtil.readResource("/valuemapstest/device.json");

DevicesConfig devicesConfig = new ObjectMapper().readerFor(DevicesConfig.class).readValue(jsonString);


DeviceStateService testee = new DeviceStateService() {
@Override
Optional<Device> findDevice(String deviceId) {
return Optional.of(devicesConfig.devices.get(0));
}
};

MQTTState state = new MQTTState();

List<DeviceBridgingRule> rules = devicesConfig.devices.get(0).capabilities.get(1).rules;
for(DeviceBridgingRule rule: rules)
{
rule.mqttState = state;
}

state.state = """
{
"power": 0,
"swing": 0,
"mode": "heat",
"targetTemp": 27,
"currentTemp": 26,
"pipeTemp": 26,
"speed": 0,
"settingsCelcius": 1,
"mute": 0
}
""";

Device deviceState = testee.getDeviceState("abc-123");
assertEquals("heat", deviceState.capabilities.get(0).state.value);

}

}
25 changes: 24 additions & 1 deletion alisamqttbridge/src/test/resources/valuemapstest/device.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
{
"alisa": { "instance": "someinstance" },
"mqtt": { "state": "statetopic" },
"valueMapsToAlisa": [ { "type": "regex", "search": "^val([0-9]+)$", "replace": "$1" } ]
"valueMapsToAlisa": [
{ "type": "regex", "search": "^val([0-9]+)$", "replace": "$1" },
{ "type": "regex", "search": "^str([0-9]+)$", "replace": "\"$1\"" }
]
},
{
"alisa": { "instance": "someinstance" },
Expand All @@ -21,6 +24,26 @@
}
]

},
{
"type": "sometype2",
"parameters": {
"instance": "someinstance"
},
"rules": [
{
"alisa": { "instance": "someinstance" },
"mqtt": { "state": "statetopic" },
"valueMapsToAlisa": [
{ "type": "regex", "search": "^.*\"mode\":\\s*\"fan\".*$", "replace": "fan_only" },
{ "type": "regex", "search": "^.*\"mode\":\\s*\"heat\".*$", "replace": "heat" },
{ "type": "regex", "search": "^.*\"mode\":\\s*\"cool\".*$", "replace": "cool" },
{ "type": "regex", "search": "^.*\"mode\":\\s*\"dry\".*$", "replace": "dry" },
{ "type": "regex", "search": "^.*\"mode\":\\s*\"auto\".*$", "replace": "auto" }
]
}
]

}
],
"properties": [
Expand Down

0 comments on commit bd8d467

Please sign in to comment.