@riddix/hamh 2.1.0-alpha.404 → 2.1.0-alpha.406

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.
@@ -168013,6 +168013,21 @@ var hvacModeToSystemMode = {
168013
168013
  function isHeatCoolOnly(modes) {
168014
168014
  return modes.includes(ClimateHvacMode.heat_cool) && !modes.includes(ClimateHvacMode.heat) && !modes.includes(ClimateHvacMode.cool);
168015
168015
  }
168016
+ var lastHvacDirection = /* @__PURE__ */ new Map();
168017
+ function getHeatCoolOnlyDirection(entity, agent) {
168018
+ const action = attributes4(entity).hvac_action;
168019
+ const homeAssistant = agent.get(HomeAssistantEntityBehavior);
168020
+ const entityId = homeAssistant.entityId;
168021
+ if (action === ClimateHvacAction.heating || action === ClimateHvacAction.preheating || action === ClimateHvacAction.defrosting || action === ClimateHvacAction.drying) {
168022
+ lastHvacDirection.set(entityId, "heating");
168023
+ return "heating";
168024
+ }
168025
+ if (action === ClimateHvacAction.cooling) {
168026
+ lastHvacDirection.set(entityId, "cooling");
168027
+ return "cooling";
168028
+ }
168029
+ return lastHvacDirection.get(entityId) ?? "heating";
168030
+ }
168016
168031
  var config4 = {
168017
168032
  // Temperature range (target_temp_low/high) only works in heat_cool mode.
168018
168033
  // In heat or cool mode, HA expects a single "temperature" value.
@@ -168031,13 +168046,14 @@ var config4 = {
168031
168046
  getCurrentTemperature: (entity, agent) => getTemp(agent, entity, "current_temperature"),
168032
168047
  getTargetHeatingTemperature: (entity, agent) => getTemp(agent, entity, "target_temp_low") ?? getTemp(agent, entity, "target_temperature") ?? getTemp(agent, entity, "temperature"),
168033
168048
  getTargetCoolingTemperature: (entity, agent) => getTemp(agent, entity, "target_temp_high") ?? getTemp(agent, entity, "target_temperature") ?? getTemp(agent, entity, "temperature"),
168034
- getSystemMode: (entity) => {
168049
+ getSystemMode: (entity, agent) => {
168035
168050
  const hvacMode = entity.state;
168036
168051
  const systemMode = hvacModeToSystemMode[hvacMode] ?? Thermostat3.SystemMode.Off;
168037
168052
  if (systemMode === Thermostat3.SystemMode.Auto) {
168038
168053
  const modes = attributes4(entity).hvac_modes ?? [];
168039
168054
  if (isHeatCoolOnly(modes)) {
168040
- return Thermostat3.SystemMode.Heat;
168055
+ const direction = getHeatCoolOnlyDirection(entity, agent);
168056
+ return direction === "cooling" ? Thermostat3.SystemMode.Cool : Thermostat3.SystemMode.Heat;
168041
168057
  }
168042
168058
  const hasHeatCool = modes.includes(ClimateHvacMode.heat_cool);
168043
168059
  if (hasHeatCool) {
@@ -168066,16 +168082,13 @@ var config4 = {
168066
168082
  if (!action) {
168067
168083
  return Thermostat3.ThermostatRunningMode.Off;
168068
168084
  }
168069
- const runningMode = hvacActionToRunningMode[action] ?? Thermostat3.ThermostatRunningMode.Off;
168070
- if (runningMode === Thermostat3.ThermostatRunningMode.Cool && isHeatCoolOnly(attributes4(entity).hvac_modes ?? [])) {
168071
- return Thermostat3.ThermostatRunningMode.Heat;
168072
- }
168073
- return runningMode;
168085
+ return hvacActionToRunningMode[action] ?? Thermostat3.ThermostatRunningMode.Off;
168074
168086
  },
168075
- getControlSequence: (entity) => {
168087
+ getControlSequence: (entity, agent) => {
168076
168088
  const modes = attributes4(entity).hvac_modes ?? [];
168077
168089
  if (isHeatCoolOnly(modes)) {
168078
- return Thermostat3.ControlSequenceOfOperation.HeatingOnly;
168090
+ const direction = getHeatCoolOnlyDirection(entity, agent);
168091
+ return direction === "cooling" ? Thermostat3.ControlSequenceOfOperation.CoolingOnly : Thermostat3.ControlSequenceOfOperation.HeatingOnly;
168079
168092
  }
168080
168093
  const hasCooling = modes.some(
168081
168094
  (m) => m === ClimateHvacMode.cool || m === ClimateHvacMode.heat_cool
@@ -168202,8 +168215,9 @@ function ClimateDevice(homeAssistantEntity) {
168202
168215
  const hasBatteryAttr = attributes7.battery_level != null || attributes7.battery != null;
168203
168216
  const hasBatteryEntity = !!homeAssistantEntity.mapping?.batteryEntity;
168204
168217
  const hasBattery = hasBatteryAttr || hasBatteryEntity;
168205
- const heatCoolOnly = attributes7.hvac_modes.includes(ClimateHvacMode.heat_cool) && !attributes7.hvac_modes.includes(ClimateHvacMode.heat) && !attributes7.hvac_modes.includes(ClimateHvacMode.cool);
168206
- const supportsCooling = heatCoolOnly ? false : coolingModes.some((mode) => attributes7.hvac_modes.includes(mode));
168218
+ const supportsCooling = coolingModes.some(
168219
+ (mode) => attributes7.hvac_modes.includes(mode)
168220
+ );
168207
168221
  const hasExplicitHeating = heatingModes.some(
168208
168222
  (mode) => attributes7.hvac_modes.includes(mode)
168209
168223
  );
@@ -172142,6 +172156,7 @@ function parseRoomData(roomsData) {
172142
172156
  const nestedRooms = parseRoomData(value);
172143
172157
  const floorIndex = floorCounter++;
172144
172158
  for (const room of nestedRooms) {
172159
+ room.mapName = key;
172145
172160
  if (typeof room.id === "number") {
172146
172161
  room.originalId = room.id;
172147
172162
  room.id = floorIndex * 1e4 + room.id;
@@ -172329,6 +172344,63 @@ function ServiceAreaServer2(initialState) {
172329
172344
  currentArea: initialState.currentArea ?? null
172330
172345
  });
172331
172346
  }
172347
+ var ServiceAreaWithMaps = ServiceAreaBehavior.with(ServiceArea3.Feature.Maps);
172348
+ var ServiceAreaServerWithMapsBase = class extends ServiceAreaWithMaps {
172349
+ selectAreas(request) {
172350
+ const { newAreas } = request;
172351
+ logger179.info(
172352
+ `ServiceArea selectAreas called with: ${JSON.stringify(newAreas)}`
172353
+ );
172354
+ const uniqueAreas = [...new Set(newAreas)];
172355
+ const supportedAreaIds = this.state.supportedAreas.map((a) => a.areaId);
172356
+ const invalidAreas = uniqueAreas.filter(
172357
+ (id) => !supportedAreaIds.includes(id)
172358
+ );
172359
+ if (invalidAreas.length > 0) {
172360
+ logger179.warn(`Invalid area IDs requested: ${invalidAreas.join(", ")}`);
172361
+ return {
172362
+ status: ServiceArea3.SelectAreasStatus.UnsupportedArea,
172363
+ statusText: `Invalid area IDs: ${invalidAreas.join(", ")}`
172364
+ };
172365
+ }
172366
+ this.state.selectedAreas = uniqueAreas;
172367
+ logger179.info(
172368
+ `ServiceArea: Stored ${uniqueAreas.length} areas for cleaning: ${uniqueAreas.join(", ")}`
172369
+ );
172370
+ return {
172371
+ status: ServiceArea3.SelectAreasStatus.Success,
172372
+ statusText: "Areas selected for cleaning"
172373
+ };
172374
+ }
172375
+ skipArea(_request) {
172376
+ return {
172377
+ status: ServiceArea3.SkipAreaStatus.InvalidInMode,
172378
+ statusText: "Skip area not supported"
172379
+ };
172380
+ }
172381
+ };
172382
+ ((ServiceAreaServerWithMapsBase2) => {
172383
+ class State extends ServiceAreaWithMaps.State {
172384
+ }
172385
+ ServiceAreaServerWithMapsBase2.State = State;
172386
+ })(ServiceAreaServerWithMapsBase || (ServiceAreaServerWithMapsBase = {}));
172387
+ function ServiceAreaServerWithMaps(initialState) {
172388
+ logger179.info(
172389
+ `Creating ServiceAreaServer with Maps: ${initialState.supportedAreas.length} areas, ${initialState.supportedMaps.length} maps`
172390
+ );
172391
+ for (const map of initialState.supportedMaps) {
172392
+ const areaCount = initialState.supportedAreas.filter(
172393
+ (a) => a.mapId === map.mapId
172394
+ ).length;
172395
+ logger179.info(` Map ${map.mapId}: "${map.name}" (${areaCount} areas)`);
172396
+ }
172397
+ return ServiceAreaServerWithMapsBase.set({
172398
+ supportedAreas: initialState.supportedAreas,
172399
+ supportedMaps: initialState.supportedMaps,
172400
+ selectedAreas: initialState.selectedAreas ?? [],
172401
+ currentArea: initialState.currentArea ?? null
172402
+ });
172403
+ }
172332
172404
 
172333
172405
  // src/matter/endpoints/legacy/vacuum/behaviors/vacuum-service-area-server.ts
172334
172406
  var logger180 = Logger.get("VacuumServiceAreaServer");
@@ -172344,10 +172416,23 @@ function toAreaId(roomId) {
172344
172416
  }
172345
172417
  return Math.abs(hash2);
172346
172418
  }
172347
- function roomsToAreas(rooms) {
172419
+ function extractMaps(rooms) {
172420
+ const seen = /* @__PURE__ */ new Map();
172421
+ for (const room of rooms) {
172422
+ if (room.mapName && !seen.has(room.mapName)) {
172423
+ seen.set(room.mapName, seen.size + 1);
172424
+ }
172425
+ }
172426
+ return Array.from(seen.entries()).map(([name, mapId]) => ({ mapId, name }));
172427
+ }
172428
+ function roomsToAreas(rooms, maps = []) {
172429
+ const mapLookup = /* @__PURE__ */ new Map();
172430
+ for (const m of maps) {
172431
+ mapLookup.set(m.name, m.mapId);
172432
+ }
172348
172433
  return rooms.map((room) => ({
172349
172434
  areaId: toAreaId(room.id),
172350
- mapId: null,
172435
+ mapId: room.mapName ? mapLookup.get(room.mapName) ?? null : null,
172351
172436
  areaInfo: {
172352
172437
  locationInfo: {
172353
172438
  locationName: room.name,
@@ -172408,7 +172493,16 @@ function createVacuumServiceAreaServer(attributes7, roomEntities, includeUnnamed
172408
172493
  );
172409
172494
  }
172410
172495
  }
172411
- const supportedAreas = roomsToAreas(rooms);
172496
+ const maps = extractMaps(rooms);
172497
+ const supportedAreas = roomsToAreas(rooms, maps);
172498
+ if (maps.length > 0) {
172499
+ return ServiceAreaServerWithMaps({
172500
+ supportedAreas,
172501
+ supportedMaps: maps,
172502
+ selectedAreas: [],
172503
+ currentArea: null
172504
+ });
172505
+ }
172412
172506
  return ServiceAreaServer2({
172413
172507
  supportedAreas,
172414
172508
  selectedAreas: [],