"""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=13.3,
        battery_current=-0.5,
        battery_power=-6,
        battery_soc=90,
        battery_state=0,
        pv_power=4,
        grid_power_l1=0,
        ac_consumption_l1=0,
    )
    assert data.battery_voltage == 13.3
    assert data.battery_power == -6


def test_solar_charger_data():
    data = SolarChargerData(
        charger_state=3,
        pv_voltage=48.57,
        pv_current=0.1,
        pv_power=6.3,
        yield_today=0.0,
        max_charge_power_today=161,
        battery_voltage=13.27,
        battery_current=2.52,
    )
    assert data.pv_voltage == 48.57
    assert data.yield_today == 0.0


def test_vebus_data():
    data = VEBusData(
        ac_input_voltage=242.3,
        ac_input_current=0.0,
        ac_input_frequency=50.10,
        ac_input_power=0,
        ac_output_voltage=0.0,
        ac_output_current=0.0,
        ac_output_frequency=49.82,
        ac_output_power=0,
        vebus_state=0,
        battery_voltage=13.27,
        battery_current=0.0,
        battery_soc=0.0,
    )
    assert data.ac_input_voltage == 242.3
    assert data.ac_input_frequency == 50.10


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=13.3,
        battery_current=0,
        battery_power=0,
        battery_soc=100,
        battery_state=0,
        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
