@riddix/hamh 2.1.0-alpha.439 → 2.1.0-alpha.440

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -165933,12 +165933,8 @@ var FanControlServerBase = class extends FeaturedBase3 {
165933
165933
  return;
165934
165934
  }
165935
165935
  this.agent.asLocalActor(() => {
165936
- const percentSetting = Math.floor(speed / this.state.speedMax * 100);
165937
- this.targetPercentSettingChanged(
165938
- percentSetting,
165939
- this.state.percentSetting,
165940
- context
165941
- );
165936
+ const percentage = Math.floor(speed / this.state.speedMax * 100);
165937
+ this.applyPercentageAction(percentage);
165942
165938
  });
165943
165939
  }
165944
165940
  targetFanModeChanged(fanMode, _oldValue, context) {
@@ -165951,16 +165947,12 @@ var FanControlServerBase = class extends FeaturedBase3 {
165951
165947
  return;
165952
165948
  }
165953
165949
  const targetFanMode = FanMode.create(fanMode, this.state.fanModeSequence);
165954
- const config10 = this.state.config;
165955
165950
  if (targetFanMode.mode === FanControl3.FanMode.Auto) {
165956
- homeAssistant.callAction(config10.setAutoMode(void 0, this.agent));
165957
- } else {
165958
- const percentage = targetFanMode.speedPercent();
165959
- this.targetPercentSettingChanged(
165960
- percentage,
165961
- this.state.percentSetting,
165962
- context
165951
+ homeAssistant.callAction(
165952
+ this.state.config.setAutoMode(void 0, this.agent)
165963
165953
  );
165954
+ } else {
165955
+ this.applyPercentageAction(targetFanMode.speedPercent());
165964
165956
  }
165965
165957
  });
165966
165958
  }
@@ -165972,45 +165964,48 @@ var FanControlServerBase = class extends FeaturedBase3 {
165972
165964
  return;
165973
165965
  }
165974
165966
  this.agent.asLocalActor(() => {
165975
- const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
165976
- if (!homeAssistant.isAvailable) {
165977
- return;
165978
- }
165979
- const config10 = this.state.config;
165980
- const supportsPercentage = config10.supportsPercentage(
165967
+ this.applyPercentageAction(percentage);
165968
+ });
165969
+ }
165970
+ applyPercentageAction(percentage) {
165971
+ const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
165972
+ if (!homeAssistant.isAvailable) {
165973
+ return;
165974
+ }
165975
+ const config10 = this.state.config;
165976
+ const supportsPercentage = config10.supportsPercentage(
165977
+ homeAssistant.entity.state,
165978
+ this.agent
165979
+ );
165980
+ if (percentage === 0) {
165981
+ homeAssistant.callAction(config10.turnOff(void 0, this.agent));
165982
+ } else if (supportsPercentage) {
165983
+ const stepSize = config10.getStepSize(
165981
165984
  homeAssistant.entity.state,
165982
165985
  this.agent
165983
165986
  );
165984
- if (percentage === 0) {
165985
- homeAssistant.callAction(config10.turnOff(void 0, this.agent));
165986
- } else if (supportsPercentage) {
165987
- const stepSize = config10.getStepSize(
165988
- homeAssistant.entity.state,
165989
- this.agent
165990
- );
165991
- const roundedPercentage = stepSize && stepSize > 0 ? Math.round(percentage / stepSize) * stepSize : percentage;
165992
- const clampedPercentage = Math.max(
165993
- stepSize ?? 1,
165994
- Math.min(100, roundedPercentage)
165987
+ const roundedPercentage = stepSize && stepSize > 0 ? Math.round(percentage / stepSize) * stepSize : percentage;
165988
+ const clampedPercentage = Math.max(
165989
+ stepSize ?? 1,
165990
+ Math.min(100, roundedPercentage)
165991
+ );
165992
+ homeAssistant.callAction(config10.turnOn(clampedPercentage, this.agent));
165993
+ } else {
165994
+ const presetModes = config10.getPresetModes(homeAssistant.entity.state, this.agent) ?? [];
165995
+ const speedPresets = presetModes.filter(
165996
+ (m) => m.toLowerCase() !== "auto"
165997
+ );
165998
+ if (speedPresets.length > 0) {
165999
+ const presetIndex = Math.min(
166000
+ Math.floor(percentage / 100 * speedPresets.length),
166001
+ speedPresets.length - 1
165995
166002
  );
165996
- homeAssistant.callAction(config10.turnOn(clampedPercentage, this.agent));
165997
- } else {
165998
- const presetModes = config10.getPresetModes(homeAssistant.entity.state, this.agent) ?? [];
165999
- const speedPresets = presetModes.filter(
166000
- (m) => m.toLowerCase() !== "auto"
166003
+ const targetPreset = speedPresets[presetIndex];
166004
+ homeAssistant.callAction(
166005
+ config10.setPresetMode(targetPreset, this.agent)
166001
166006
  );
166002
- if (speedPresets.length > 0) {
166003
- const presetIndex = Math.min(
166004
- Math.floor(percentage / 100 * speedPresets.length),
166005
- speedPresets.length - 1
166006
- );
166007
- const targetPreset = speedPresets[presetIndex];
166008
- homeAssistant.callAction(
166009
- config10.setPresetMode(targetPreset, this.agent)
166010
- );
166011
- }
166012
166007
  }
166013
- });
166008
+ }
166014
166009
  }
166015
166010
  targetAirflowDirectionChanged(airflowDirection, _oldValue, context) {
166016
166011
  if (transactionIsOffline(context)) {