# Class DeviceService

Namespace
  adas_core.Application.Services

Assembly
  adas-core.Application.dll

Provides the concrete implementation of the IDeviceService contract, handling device-related service operations defined by the interface.

    public class DeviceService : IDeviceService

Inheritance
  object
  DeviceService

Implements
  IDeviceService

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## Constructors

### DeviceService(IDeviceRepository, IPointOfCareService, ILogger<DeviceService>, IObservationService, IConfigObservationService, IAlarmService)

    public DeviceService(IDeviceRepository deviceRepository, IPointOfCareService pointOfCareService, ILogger<DeviceService> logger, IObservationService observationService, IConfigObservationService configObservationService, IAlarmService alarmService)

#### Parameters

`deviceRepository` IDeviceRepository
`pointOfCareService` IPointOfCareService
`logger` ILogger<DeviceService>
`observationService` IObservationService
`configObservationService` IConfigObservationService
`alarmService` IAlarmService

## Methods

### Create(DeviceDto)

Creates a new device entity from the provided DTO, sets the creation and update timestamps to the current UTC time, and persists it via the device repository.

    public Task<Device?> Create(DeviceDto deviceDto)

#### Parameters

`deviceDto` DeviceDto

  The data transfer object containing the device information to be mapped and stored.

#### Returns

Task<Device>

  The created Device entity after successful insertion, or null if the device could not be created.

### Delete(ObjectId)

Deletes an object identified by the specified `objectId` by delegating to the device repository. Returns `true` when the repository's delete operation yields a non-null result, and `false` when the result is `null` (e.g., the object was not found or could not be deleted).

    public Task<bool> Delete(ObjectId objectId)

#### Parameters

`objectId` ObjectId

  The unique identifier of the object to delete.

#### Returns

Task<bool>

  A task that resolves to `true` if the object was deleted; otherwise, `false`.

### ReceiveEvent(DeviceDto)

Processes an incoming device event by locating an existing device or creating a new one, then handling device-type-specific logic. Looks up the device using the MAC address, serial number, UUID, or key in that order, falling back to creating a new record when no match is found. When the device is a button, additional button management logic is invoked.

    public Task<Device?> ReceiveEvent(DeviceDto deviceDto)

#### Parameters

`deviceDto` DeviceDto

  The data transfer object containing the device information from the event, used for lookup and creation.

#### Returns

Task<Device>

  The existing or newly created Device associated with the event.

### ToEntity(DeviceDto)

Converts a DeviceDto into a Device entity by mapping its properties. Applies a fallback to an empty list when `PointOfCareIds` is null, and to a new DeviceSettings instance when `Settings` is null.

    public Device ToEntity(DeviceDto dto)

#### Parameters

`dto` DeviceDto

  The data transfer object containing the device information to convert.

#### Returns

Device

  A new Device entity populated with the values from the supplied DTO.

### Update(DeviceDto)

Updates an existing device by mapping the provided DTO to a device entity, setting the update timestamp, and persisting the changes through the repository.

    public Task<Device?> Update(DeviceDto deviceDto)

#### Parameters

`deviceDto` DeviceDto

  The data transfer object containing the updated device information.

#### Returns

Task<Device>

  The updated Device entity, or `null` if no device is returned.