topic); if ($parsed === null) { return; } [$prefix, $component] = $parsed; // Unknown devices are handled by discovery (Phase 4), not silently created here. $device = Device::where('config->mqtt_prefix', $prefix)->first(); if ($device === null) { return; } $data = json_decode($this->payload, true); if (! is_array($data)) { return; } $device->forceFill(['last_seen_at' => now()])->save(); foreach (ShellyNormalizer::normalize($component, $data) as $update) { $entity = $device->entities()->firstOrCreate( ['key' => $update['key']], ['type' => $update['type']], ); DeviceState::updateOrCreate( ['entity_id' => $entity->id], ['state' => $update['state']], ); DeviceStateChanged::dispatch($device->uuid, $entity->key, $update['state']); } } }