# Path: BAC0/core/devices/local/models.py
# def analog_value(**kwargs):
#     kwargs["name"] = set_default_if_not_provided("name", "AV", **kwargs)
#     kwargs["objectType"] = AnalogValueObject
#     kwargs["instance"] = set_default_if_not_provided("instance", 0, **kwargs)
#     kwargs["is_commandable"] = True
#     return analog(**kwargs)


import BAC0
import time
from BAC0.core.devices.local.models import analog_value
from bacpypes.primitivedata import Real

device = BAC0.lite("192.168.211.55/24", deviceId=123)
client = BAC0.lite("192.168.212.12/24")

new_obj = analog_value()
new_obj.add_objects_to_application(device)

# From Server
dev_av = device.this_application.get_object_name("AV")
print(dev_av.covIncrement)

# From client
dev = dev = BAC0.device("192.168.211.55", 123, client, poll=0)
av = dev["AV"]
dev["AV"].subscribe_cov(lifetime=0)

print()
while True:
    print(dev["AV"])
    time.sleep(1)

# Path: BAC0/core/devices/local/models.py
# def analog_value(**kwargs):
#     kwargs["name"] = set_default_if_not_provided("name", "AV", **kwargs)
#     kwargs["objectType"] = AnalogValueObject
#     kwargs["instance"] = set_default_if_not_provided("instance", 0, **kwargs)
#     kwargs["is_commandable"] = True
#     return analog(**kwargs)


# Path: tests/manualtest_cov.py
import BAC0
import time
from BAC0.core.devices.local.models import analog_value
from bacpypes.primitivedata import Real


device = BAC0.lite("192.168.211.55/24", deviceId=123)
client = BAC0.lite("192.168.212.12/24")

new_obj = analog_value()
new_obj.add_objects_to_application(device)

# From Server
dev_av = device.this_application.get_object_name("AV")
print(dev_av.covIncrement)

# From client
dev = dev = BAC0.device("192.168.211.55", 123, client, poll=0)
av = dev["AV"]
dev["AV"].subscribe_cov(lifetime=0)

print()
while True:
    print(dev["AV"])
    time.sleep(1)

    dev["AV"] += 1