"""Tests for aiovictron data models."""

from aiovictron.models import (
    DeviceIdentity,
    SolarChargerData,
    SystemData,
    VEBusData,
    VictronData,
)


def test_device_identity_frozen():
    identity = DeviceIdentity(unit_id=100, device_type="system", product_name="System")
    assert identity.unit_id == 100
    assert identity.device_type == "system"


def test_system_data():
    data = SystemData(
        battery_voltage=26.5,
        battery_current=-3.2,
        battery_power=-85,
        battery_soc=78,
        battery_state=4,
        pv_power=350,
        grid_power_l1=0,
        ac_consumption_l1=120,
    )
    assert data.battery_voltage == 26.5
    assert data.battery_power == -85


def test_solar_charger_data():
    data = SolarChargerData(
        charger_state=3,
        pv_voltage=38.5,
        pv_current=9.1,
        pv_power=350,
        yield_today=1.8,
        max_charge_power_today=420,
        battery_voltage=26.8,
        battery_current=12.5,
    )
    assert data.pv_power == 350
    assert data.yield_today == 1.8


def test_vebus_data():
    data = VEBusData(
        ac_input_voltage=240.1,
        ac_input_current=2.5,
        ac_input_frequency=50.01,
        ac_input_power=600,
        ac_output_voltage=240.0,
        ac_output_current=3.1,
        ac_output_frequency=50.00,
        ac_output_power=744,
        vebus_state=9,
        battery_voltage=26.5,
        battery_current=-8.0,
        battery_temperature=22.5,
        battery_soc=78.0,
        dc_power=-200,
    )
    assert data.ac_input_voltage == 240.1
    assert data.vebus_state == 9


def test_victron_data_optional_fields():
    data = VictronData()
    assert data.system is None
    assert data.solar_charger is None
    assert data.vebus is None
    assert data.discovered_devices == ()


def test_victron_data_with_system():
    system = SystemData(
        battery_voltage=26.5,
        battery_current=0,
        battery_power=0,
        battery_soc=100,
        battery_state=5,
        pv_power=0,
        grid_power_l1=0,
        ac_consumption_l1=0,
    )
    data = VictronData(system=system)
    assert data.system is not None
    assert data.system.battery_soc == 100
