(entity: Group | Device, payload: KeyValue, stateChangeReason?: StateChangeReason)
| 380 | } |
| 381 | |
| 382 | @bind async publishEntityState(entity: Group | Device, payload: KeyValue, stateChangeReason?: StateChangeReason): Promise<void> { |
| 383 | let message: Zigbee2MQTTAPI["{friendlyName}"] = {...payload}; |
| 384 | |
| 385 | // Update state cache with new state. |
| 386 | const newState = this.state.set(entity, payload, stateChangeReason); |
| 387 | |
| 388 | if (settings.get().advanced.cache_state) { |
| 389 | // Add cached state to payload |
| 390 | message = newState; |
| 391 | } |
| 392 | |
| 393 | const options: MakePartialExcept<MqttPublishOptions, "clientOptions" | "meta"> = { |
| 394 | clientOptions: { |
| 395 | retain: utils.getObjectProperty(entity.options, "retain", false), |
| 396 | qos: utils.getObjectProperty(entity.options, "qos", 0), |
| 397 | }, |
| 398 | meta: { |
| 399 | isEntityState: true, |
| 400 | }, |
| 401 | }; |
| 402 | const retention = utils.getObjectProperty<number | false>(entity.options, "retention", false); |
| 403 | |
| 404 | if (retention !== false) { |
| 405 | options.clientOptions.properties = {messageExpiryInterval: retention}; |
| 406 | } |
| 407 | |
| 408 | if (entity.isDevice() && settings.get().mqtt.include_device_information) { |
| 409 | message.device = { |
| 410 | friendlyName: entity.name, |
| 411 | model: entity.definition?.model, |
| 412 | ieeeAddr: entity.ieeeAddr, |
| 413 | networkAddress: entity.zh.networkAddress, |
| 414 | type: entity.zh.type, |
| 415 | manufacturerID: entity.zh.manufacturerID, |
| 416 | powerSource: entity.zh.powerSource, |
| 417 | applicationVersion: entity.zh.applicationVersion, |
| 418 | stackVersion: entity.zh.stackVersion, |
| 419 | zclVersion: entity.zh.zclVersion, |
| 420 | hardwareVersion: entity.zh.hardwareVersion, |
| 421 | dateCode: entity.zh.dateCode, |
| 422 | softwareBuildID: entity.zh.softwareBuildID, |
| 423 | // Manufacturer name can contain \u0000, remove this. |
| 424 | // https://github.com/home-assistant/core/issues/85691 |
| 425 | /* v8 ignore next */ |
| 426 | manufacturerName: entity.zh.manufacturerName?.split("\u0000")[0], |
| 427 | }; |
| 428 | } |
| 429 | |
| 430 | // Add lastseen |
| 431 | const lastSeen = settings.get().advanced.last_seen; |
| 432 | if (entity.isDevice() && lastSeen !== "disable" && entity.zh.lastSeen) { |
| 433 | message.last_seen = utils.formatDate(entity.zh.lastSeen, lastSeen); |
| 434 | } |
| 435 | |
| 436 | // Add device linkquality. |
| 437 | if (entity.isDevice() && entity.zh.linkquality !== undefined) { |
| 438 | message.linkquality = entity.zh.linkquality; |
| 439 | } |
no test coverage detected