generated from ludeeus/integration_blueprint
-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_sensor.py
96 lines (74 loc) · 2.66 KB
/
test_sensor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"""Tests sensor."""
import datetime
from homeassistant.components.sensor import SensorEntityDescription
from homeassistant.core import HomeAssistant
from homeassistant.util import dt
from pytest_homeassistant_custom_component.common import async_fire_time_changed
from custom_components.kamstrup_403.const import DOMAIN
from custom_components.kamstrup_403.sensor import (
KamstrupDateSensor,
KamstrupGasSensor,
KamstrupMeterSensor,
)
from . import setup_component
async def test_kamstrup_gas_sensor(hass: HomeAssistant, bypass_get_data):
"""Test for gas sensor."""
config_entry = await setup_component(hass)
sensor = KamstrupGasSensor(
hass.data[DOMAIN][config_entry.entry_id],
config_entry.entry_id,
SensorEntityDescription(
key="gas",
name="Heat Energy to Gas",
),
)
# Mock data.
sensor.coordinator.data[60] = {"value": 1234, "unit": "GJ"}
async_fire_time_changed(
hass,
datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(seconds=1),
)
await hass.async_block_till_done()
assert sensor.state == 1234
async def test_kamstrup_meter_sensor(hass: HomeAssistant, bypass_get_data):
"""Test for base sensor."""
config_entry = await setup_component(hass)
sensor = KamstrupMeterSensor(
hass.data[DOMAIN][config_entry.entry_id],
config_entry.entry_id,
SensorEntityDescription(
key="60",
name="Heat Energy (E1)",
),
)
# Mock data.
sensor.coordinator.data[60] = {"value": 1234, "unit": "GJ"}
async_fire_time_changed(
hass,
datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(seconds=1),
)
await hass.async_block_till_done()
assert sensor.int_key == 60
assert sensor.state == 1234
assert sensor.native_unit_of_measurement == "GJ"
async def test_kamstrup_date_sensor(hass: HomeAssistant, bypass_get_data):
"""Test for date sensor."""
config_entry = await setup_component(hass)
sensor = KamstrupDateSensor(
hass.data[DOMAIN][config_entry.entry_id],
config_entry.entry_id,
SensorEntityDescription(
key="140", # 0x008C
name="MinFlowDate_M",
),
)
# Mock data.
sensor.coordinator.data[140] = {"value": 230123.0, "unit": "yy:mm:dd"}
async_fire_time_changed(
hass,
datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(seconds=1),
)
await hass.async_block_till_done()
assert sensor.int_key == 140
assert sensor.state == dt.as_local(datetime.datetime(2023, 1, 23))
assert sensor.native_unit_of_measurement is None