import type { ISimpleLocalConfig, ISimpleLocalIntegrationProfile, ISimpleLocalSnapshot, TSimpleLocalRawData } from '../../core/index.js';

export const onewireDomain = "onewire";
export const onewireDefaultName = "1-Wire";
export const onewireDefaultPort = 4304;

export type TOnewireRawData = TSimpleLocalRawData;
export interface IOnewireSnapshot extends ISimpleLocalSnapshot {}
export interface IOnewireConfig extends ISimpleLocalConfig {
  url?: string;
  macAddress?: string;
  deviceId?: string;
}
export interface IHomeAssistantOnewireConfig extends IOnewireConfig {}

export const onewireProfile: ISimpleLocalIntegrationProfile = {
  domain: onewireDomain,
  displayName: "1-Wire",
  manufacturer: "1-Wire",
  model: "1-Wire local integration",
  defaultName: onewireDefaultName,
  defaultPort: onewireDefaultPort,
  defaultProtocol: 'tcp',
  status: "control-runtime",
  platforms: [
    "binary_sensor",
    "select",
    "sensor",
    "switch",
  ],
  serviceDomains: [
    "select",
    "switch",
  ],
  controlServices: [
    "select_option",
    "toggle",
    "turn_off",
    "turn_on",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "onewire",
    "1-Wire",
    "Onewire",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/onewire",
    "upstreamDomain": "onewire",
    "integrationType": "hub",
    "iotClass": "local_polling",
    "qualityScale": "silver",
    "requirements": [
      "aio-ownet==0.0.5",
    ],
    "codeowners": [
      "@garbled1",
      "@epenet",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/onewire",
    "loggers": [
      "aio_ownet",
    ],
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "select_option",
        "toggle",
        "turn_off",
        "turn_on",
      ],
      "platforms": [
        "binary_sensor",
        "select",
        "sensor",
        "switch",
      ],
      "controls": "native OWServer writes for entity device_file paths; injected client.execute or commandExecutor remains supported",
    },
    "localApi": {
      "status": "Native OWServer/OWNet TCP polling and path writes are implemented for manual host/port configurations; direct USB/serial bus master access is not implemented.",
      "implemented": [
        "native OWServer/OWNet TCP polling on port 4304 for device discovery, family/type reads, and supported HA entity value paths",
        "native OWServer/OWNet write support for switch/select control when a device_file/path is supplied or resolved from the current native snapshot",
        "manual local setup for 1-Wire endpoints, snapshots, rawData, snapshotProvider, and injected native clients",
        "runtime mapping for 1-Wire device snapshots and Home Assistant platform metadata",
        "safe command delegation to injected client.execute or commandExecutor when no live OWServer host is configured",
      ],
      "explicitUnsupported": [
        "direct USB/serial/I2C 1-Wire adapter access without an OWServer TCP endpoint; this requires OS bus-master drivers or Python/OWFS bindings outside existing repo deps",
        "OWServer zeroconf discovery probing and Home Assistant registry repair/migration flows",
        "claiming command success for a 1-Wire switch/select without an OWServer path/device_file or injected client.execute/commandExecutor",
      ],
    },
  },
};
