Skip to content

Commit

Permalink
Release 0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Luligu committed Dec 7, 2024
1 parent c8bef2c commit afcd62a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ All notable changes to this project will be documented in this file.

If you like this project and find it useful, please consider giving it a star on GitHub at https://github.com/Luligu/matterbridge-hass and sponsoring it.

## [0.0.3] - 2024-12-06
## [0.0.3] - 2024-12-07

### Added

- [climate]: Add state heat_cool and attributes target_temp_low target_temp_high to domain climate.

### Changed

- [homeassistant]: Changed to debug the log of processing event.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Supported devices:
- lock (with state locked/locking/unlocking/unlocked)
- fan (with state on/off and attributes percentage/preset_mode)
- cover (with state open/close/opening/closing and attribute current_position)
- climate (with state off/heat/cool and attribute temperature/current_temperature)
- climate (with state off/heat/cool/heat_cool and attribute temperature/current_temperature/target_temp_low/target_temp_high)

> **Warning:** Since this plugin takes the devices from Home Assistant, it cannot be paired back to Home Assistant. This would lead to duplicate devices! If you run Matterbridge like a Home Assistant Add-on and also use other plugins to expose their devices to Home Assistant, then change to child bridge mode and pair the other plugins to Home Assistant and this plugin wherever you need it.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matterbridge-hass",
"version": "0.0.3-dev.1",
"version": "0.0.3",
"description": "Matterbridge hass plugin",
"author": "https://github.com/Luligu",
"license": "Apache-2.0",
Expand Down
28 changes: 24 additions & 4 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const hassUpdateStateConverter: { domain: string; state: string; clusterId: Clus
{ domain: 'climate', state: 'off', clusterId: ThermostatCluster.id, attribute: 'systemMode', value: Thermostat.SystemMode.Off },
{ domain: 'climate', state: 'heat', clusterId: ThermostatCluster.id, attribute: 'systemMode', value: Thermostat.SystemMode.Heat },
{ domain: 'climate', state: 'cool', clusterId: ThermostatCluster.id, attribute: 'systemMode', value: Thermostat.SystemMode.Cool },
{ domain: 'climate', state: 'heat_cool', clusterId: ThermostatCluster.id, attribute: 'systemMode', value: Thermostat.SystemMode.Auto },
];

// Update Home Assistant attributes to Matterbridge device attributes
Expand Down Expand Up @@ -128,8 +129,10 @@ const hassUpdateAttributeConverter: { domain: string; with: string; clusterId: C
{ domain: 'cover', with: 'current_position', clusterId: WindowCoveringCluster.id, attribute: 'currentPositionLiftPercent100ths', converter: (value: number) => (isValidNumber(value, 0, 100) ? Math.round(10000 - value * 100) : null) },
{ domain: 'cover', with: 'current_position', clusterId: WindowCoveringCluster.id, attribute: 'targetPositionLiftPercent100ths', converter: (value: number) => (isValidNumber(value, 0, 100) ? Math.round(10000 - value * 100) : null) },

{ domain: 'climate', with: 'temperature', clusterId: ThermostatCluster.id, attribute: 'occupiedHeatingSetpoint', converter: (value: number, state: HassState) => (isValidNumber(value) && state.state === 'heat' ? value * 100 : null) },
{ domain: 'climate', with: 'temperature', clusterId: ThermostatCluster.id, attribute: 'occupiedCoolingSetpoint', converter: (value: number, state: HassState) => (isValidNumber(value) && state.state === 'cool' ? value * 100 : null) },
{ domain: 'climate', with: 'temperature', clusterId: ThermostatCluster.id, attribute: 'occupiedHeatingSetpoint', converter: (value: number, state: HassState) => (isValidNumber(value) && state.state === 'heat' ? value * 100 : null) },
{ domain: 'climate', with: 'temperature', clusterId: ThermostatCluster.id, attribute: 'occupiedCoolingSetpoint', converter: (value: number, state: HassState) => (isValidNumber(value) && state.state === 'cool' ? value * 100 : null) },
{ domain: 'climate', with: 'target_temp_high', clusterId: ThermostatCluster.id, attribute: 'occupiedCoolingSetpoint', converter: (value: number, state: HassState) => (isValidNumber(value) && state.state === 'heat_cool' ? value * 100 : null) },
{ domain: 'climate', with: 'target_temp_low', clusterId: ThermostatCluster.id, attribute: 'occupiedHeatingSetpoint', converter: (value: number, state: HassState) => (isValidNumber(value) && state.state === 'heat_cool' ? value * 100 : null) },
{ domain: 'climate', with: 'current_temperature', clusterId: ThermostatCluster.id, attribute: 'localTemperature', converter: (value: number) => (isValidNumber(value) ? value * 100 : null) },
];

Expand Down Expand Up @@ -428,7 +431,22 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
}
// Special case for climate domain: configure the thermostat cluster
if (domain === 'climate') {
if (isValidArray(hassState?.attributes['hvac_modes']) && hassState.attributes['hvac_modes'].includes('heat') && !hassState.attributes['hvac_modes'].includes('cool'))
if (isValidArray(hassState?.attributes['hvac_modes']) && hassState.attributes['hvac_modes'].includes('heat_cool'))
child.createDefaultThermostatClusterServer(
hassState?.attributes['current_temperature'] as number | undefined,
hassState?.attributes['target_temp_low'] as number | undefined,
hassState?.attributes['target_temp_high'] as number | undefined,
0,
hassState?.attributes['min_temp'] as number | undefined,
hassState?.attributes['max_temp'] as number | undefined,
hassState?.attributes['min_temp'] as number | undefined,
hassState?.attributes['max_temp'] as number | undefined,
);
else if (
isValidArray(hassState?.attributes['hvac_modes']) &&
hassState.attributes['hvac_modes'].includes('heat') &&
!hassState.attributes['hvac_modes'].includes('cool')
)
child.createDefaultHeatingThermostatClusterServer(
hassState?.attributes['current_temperature'] as number | undefined,
hassState?.attributes['temperature'] as number | undefined,
Expand Down Expand Up @@ -534,6 +552,8 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
override async onShutdown(reason?: string) {
this.log.info(`Shutting down platform ${idn}${this.config.name}${rs}${nf}: ${reason ?? ''}`);

this.ha.close();

if (this.config.unregisterOnShutdown === true) await this.unregisterAllDevices();
}

Expand Down Expand Up @@ -589,7 +609,7 @@ export class HomeAssistantPlatform extends MatterbridgeDynamicPlatform {
if (hassUpdateState) {
await mbDevice.setAttribute(hassUpdateState.clusterId, hassUpdateState.attribute, hassUpdateState.value, mbDevice.log, endpoint);
} else {
mbDevice.log.warn(`Update ${CYAN}${domain}${wr}:${CYAN}${new_state.state}${wr} not supported for entity ${entityId}`);
mbDevice.log.warn(`Update state ${CYAN}${domain}${wr}:${CYAN}${new_state.state}${wr} not supported for entity ${entityId}`);
}
// Update attributes of the device
const hassUpdateAttributes = hassUpdateAttributeConverter.filter((updateAttribute) => updateAttribute.domain === domain);
Expand Down

0 comments on commit afcd62a

Please sign in to comment.