"""Fixtures for testing victron_ble."""

from home_assistant_bluetooth import BluetoothServiceInfo

NOT_VICTRON_SERVICE_INFO = BluetoothServiceInfo(
    name="Not it",
    address="61DE521B-F0BF-9F44-64D4-75BBE1738105",
    rssi=-63,
    manufacturer_data={3234: b"\x00\x01"},
    service_data={},
    service_uuids=[],
    source="local",
)

VICTRON_TEST_WRONG_TOKEN = "00000000000000000000000000000000"

# battery monitor
VICTRON_BATTERY_MONITOR_SERVICE_INFO = BluetoothServiceInfo(
    name="Battery Monitor",
    address="01:02:03:04:05:07",
    rssi=-60,
    manufacturer_data={
        0x02E1: bytes.fromhex("100289a302b040af925d09a4d89aa0128bdef48c6298a9")
    },
    service_data={},
    service_uuids=[],
    source="local",
)
VICTRON_BATTERY_MONITOR_TOKEN = "aff4d0995b7d1e176c0c33ecb9e70dcd"
VICTRON_BATTERY_MONITOR_SENSORS = {
    "battery_monitor_aux_mode": "disabled",
    "battery_monitor_consumed_ampere_hours": "-50.0",
    "battery_monitor_current": "0.0",
    "battery_monitor_remaining_minutes": "unknown",
    "battery_monitor_state_of_charge": "50.0",
    "battery_monitor_voltage": "12.53",
    "battery_monitor_alarm": "none",
    "battery_monitor_temperature": "unknown",
    "battery_monitor_starter_voltage": "unknown",
    "battery_monitor_midpoint_voltage": "unknown",
}

# Battery Sense

VICTRON_BATTERY_SENSE_SERVICE_INFO = BluetoothServiceInfo(
    name="Battery Sense",
    address="01:02:03:04:05:14",
    rssi=-60,
    manufacturer_data={
        0x02E1: bytes.fromhex("1000a4a3025f150d8dcbff517f30eb65e76b22a04ac4e1")
    },
    service_data={},
    service_uuids=[],
    source="local",
)

VICTRON_BATTERY_SENSE_TOKEN = "0da694539597f9cf6c613cde60d7bf05"

# DC/DC converter

VICTRON_DC_DC_CONVERTER_SERVICE_INFO = BluetoothServiceInfo(
    name="DC/DC Converter",
    address="01:02:03:04:05:08",
    rssi=-60,
    manufacturer_data={
        0x02E1: bytes.fromhex("1000c0a304121d64ca8d442b90bbdf6a8cba"),
    },
    service_data={},
    service_uuids=[],
    source="local",
)

VICTRON_DC_DC_CONVERTER_TOKEN = "64ba49f1a8562e45197a8e1fe50d7658"

# DC energy meter

VICTRON_DC_ENERGY_METER_SERVICE_INFO = BluetoothServiceInfo(
    name="DC Energy Meter",
    address="01:02:03:04:05:09",
    rssi=-60,
    manufacturer_data={
        0x02E1: bytes.fromhex("100289a30d787fafde83ccec982199fd815286"),
    },
    service_data={},
    service_uuids=[],
    source="local",
)

VICTRON_DC_ENERGY_METER_TOKEN = "aff4d0995b7d1e176c0c33ecb9e70dcd"

VICTRON_DC_ENERGY_METER_SENSORS = {
    "dc_energy_meter_meter_type": "dc_dc_charger",
    "dc_energy_meter_aux_mode": "starter_voltage",
    "dc_energy_meter_current": "0.0",
    "dc_energy_meter_voltage": "12.52",
    "dc_energy_meter_starter_voltage": "-0.01",
    "dc_energy_meter_alarm": "none",
    "dc_energy_meter_temperature": "unknown",
}

# Inverter

VICTRON_INVERTER_SERVICE_INFO = BluetoothServiceInfo(
    name="Inverter",
    address="01:02:03:04:05:10",
    rssi=-60,
    manufacturer_data={
        0x02E1: bytes.fromhex("1003a2a2031252dad26f0b8eb39162074d140df410"),
    },  # not a valid advertisement, but model id mangled to match inverter
    service_data={},
    service_uuids=[],
    source="local",
)

VICTRON_INVERTER_RS_SERVICE_INFO = BluetoothServiceInfo(
    name="Inverter RS",
    address="01:02:03:04:05:16",
    rssi=-60,
    manufacturer_data={
        0x02E1: bytes.fromhex("1000a2a2061252dad26f0b8eb39162074d140df410"),
    },
    service_data={},
    service_uuids=[],
    source="local",
)

# SmartLithium (8-cell, 24V)

VICTRON_SMART_LITHIUM_SERVICE_INFO = BluetoothServiceInfo(
    name="Smart Lithium",
    address="01:02:03:04:05:13",
    rssi=-60,
    manufacturer_data={
        0x02E1: bytes.fromhex(
            "100000a3057856aadf9983c6e47496d1bce1003992e56ba4"
            "bab0cf5f4d013b8cfd21b3bd353fba2216ceb2aae268ebca"
            "3f8ed9bfcd1965ba"
        )
    },
    service_data={},
    service_uuids=[],
    source="local",
)

VICTRON_SMART_LITHIUM_TOKEN = "aaaa000000000000000000000000bbbb"

# Solar charger

VICTRON_SOLAR_CHARGER_SERVICE_INFO = BluetoothServiceInfo(
    name="Solar Charger",
    address="01:02:03:04:05:11",
    rssi=-60,
    manufacturer_data={
        0x02E1: bytes.fromhex("100242a0016207adceb37b605d7e0ee21b24df5c"),
    },
    service_data={},
    service_uuids=[],
    source="local",
)

VICTRON_SOLAR_CHARGER_TOKEN = "adeccb947395801a4dd45a2eaa44bf17"

VICTRON_SOLAR_CHARGER_SENSORS = {
    "solar_charger_charge_state": "absorption",
    "solar_charger_battery_voltage": "13.88",
    "solar_charger_battery_current": "1.4",
    "solar_charger_yield_today": "30",
    "solar_charger_solar_power": "19",
    "solar_charger_external_device_load": "0.0",
}

# ve.bus

VICTRON_VEBUS_SERVICE_INFO = BluetoothServiceInfo(
    name="Inverter Charger",
    address="01:02:03:04:05:06",
    rssi=-60,
    manufacturer_data={
        0x02E1: bytes.fromhex("100380270c1252dad26f0b8eb39162074d140df410")
    },
    service_data={},
    service_uuids=[],
    source="local",
)

VICTRON_VEBUS_TOKEN = "da3f5fa2860cb1cf86ba7a6d1d16b9dd"

# Same device type header as VEBus (100380) but garbled encrypted payload.
# Device type will be recognized but decryption will fail.
VICTRON_VEBUS_BAD_KEY_SERVICE_INFO = BluetoothServiceInfo(
    name="Inverter Charger",
    address="01:02:03:04:05:06",
    rssi=-60,
    manufacturer_data={
        0x02E1: bytes.fromhex("100380270cFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")
    },
    service_data={},
    service_uuids=[],
    source="local",
)

# Same DC/DC converter but with OffReason=0x81 (NO_INPUT_POWER|ENGINE_SHUTDOWN),
# a real bitmask combination that the current OffReason enum doesn't handle.
# The key check byte is valid so validate_advertisement_key passes, but
# parsing raises ValueError → sparse update (signal strength only).
VICTRON_DC_DC_CONVERTER_UNKNOWN_OFF_REASON_SERVICE_INFO = BluetoothServiceInfo(
    name="DC/DC Converter",
    address="01:02:03:04:05:08",
    rssi=-60,
    manufacturer_data={0x02E1: bytes.fromhex("1000c0a304121d64ca8d442b90bbde6a8cba")},
    service_data={},
    service_uuids=[],
    source="local",
)

# Same Victron manufacturer data prefix but with an unrecognized mode byte
# (0xEE at offset 4).  detect_device_type returns None for this payload,
# so validate_advertisement_key would also return False.  The reauth logic
# must treat this as neutral (not a key failure).
VICTRON_VEBUS_UNRECOGNIZED_MODE_SERVICE_INFO = BluetoothServiceInfo(
    name="Inverter Charger",
    address="01:02:03:04:05:06",
    rssi=-60,
    manufacturer_data={
        0x02E1: bytes.fromhex("10038027ee1252dad26f0b8eb39162074d140df410")
    },
    service_data={},
    service_uuids=[],
    source="local",
)

VICTRON_VEBUS_SENSORS = {
    "inverter_charger_device_state": "float",
    "inverter_charger_battery_voltage": "14.45",
    "inverter_charger_battery_current": "23.2",
    "inverter_charger_ac_in_state": "AC_IN_1",
    "inverter_charger_ac_in_power": "1459",
    "inverter_charger_ac_out_power": "1046",
    "inverter_charger_battery_temperature": "32",
    "inverter_charger_state_of_charge": "unknown",
}

# Smart Battery Protect

VICTRON_SMART_BATTERY_PROTECT_SERVICE_INFO = BluetoothServiceInfo(
    name="Smart Battery Protect",
    address="01:02:03:04:05:15",
    rssi=-60,
    manufacturer_data={
        0x02E1: bytes.fromhex("1080b0a3093523fadedea38b1af8bcbde91ca8b6dbb60e")
    },
    service_data={},
    service_uuids=[],
    source="local",
)

VICTRON_SMART_BATTERY_PROTECT_TOKEN = "fac570d66380b797a5b7543758be00e4"

# AC charger

VICTRON_AC_CHARGER_SERVICE_INFO = BluetoothServiceInfo(
    name="Smart Charger",
    address="01:02:03:04:05:12",
    rssi=-60,
    manufacturer_data={
        0x02E1: bytes.fromhex("100030a308f926c1b5170a0d2280335bf12d5ed083")
    },
    service_data={},
    service_uuids=[],
    source="local",
)

VICTRON_AC_CHARGER_TOKEN = "c129cf8f75c3fe5a1655b481e205fb7d"
