Skip to content

Commit

Permalink
Bump hatasmota to 0.7.3 (#100169)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery committed Sep 12, 2023
1 parent 27c430b commit 5bcb4f0
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 4 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/tasmota/manifest.json
Expand Up @@ -8,5 +8,5 @@
"iot_class": "local_push",
"loggers": ["hatasmota"],
"mqtt": ["tasmota/discovery/#"],
"requirements": ["HATasmota==0.7.2"]
"requirements": ["HATasmota==0.7.3"]
}
1 change: 0 additions & 1 deletion homeassistant/components/tasmota/sensor.py
Expand Up @@ -216,7 +216,6 @@
hc.LIGHT_LUX: LIGHT_LUX,
hc.MASS_KILOGRAMS: UnitOfMass.KILOGRAMS,
hc.PERCENTAGE: PERCENTAGE,
hc.POWER_FACTOR: None,
hc.POWER_WATT: UnitOfPower.WATT,
hc.PRESSURE_HPA: UnitOfPressure.HPA,
hc.REACTIVE_POWER: POWER_VOLT_AMPERE_REACTIVE,
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Expand Up @@ -29,7 +29,7 @@ DoorBirdPy==2.1.0
HAP-python==4.7.1

# homeassistant.components.tasmota
HATasmota==0.7.2
HATasmota==0.7.3

# homeassistant.components.mastodon
Mastodon.py==1.5.1
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Expand Up @@ -28,7 +28,7 @@ DoorBirdPy==2.1.0
HAP-python==4.7.1

# homeassistant.components.tasmota
HATasmota==0.7.2
HATasmota==0.7.3

# homeassistant.components.doods
# homeassistant.components.generic
Expand Down
214 changes: 214 additions & 0 deletions tests/components/tasmota/test_sensor.py
Expand Up @@ -137,6 +137,27 @@
}
}

NUMBERED_SENSOR_CONFIG = {
"sn": {
"Time": "2020-09-25T12:47:15",
"ANALOG": {
"Temperature1": 2.4,
"Temperature2": 2.4,
"Illuminance3": 2.4,
},
"TempUnit": "C",
}
}

NUMBERED_SENSOR_CONFIG_2 = {
"sn": {
"Time": "2020-09-25T12:47:15",
"ANALOG": {
"CTEnergy1": {"Energy": 0.5, "Power": 2300, "Voltage": 230, "Current": 10},
},
"TempUnit": "C",
}
}

TEMPERATURE_SENSOR_CONFIG = {
"sn": {
Expand Down Expand Up @@ -343,6 +364,118 @@
},
),
),
(
NUMBERED_SENSOR_CONFIG,
[
"sensor.tasmota_analog_temperature1",
"sensor.tasmota_analog_temperature2",
"sensor.tasmota_analog_illuminance3",
],
(
(
'{"ANALOG":{"Temperature1":1.2,"Temperature2":3.4,'
'"Illuminance3": 5.6}}'
),
(
'{"StatusSNS":{"ANALOG":{"Temperature1": 7.8,"Temperature2": 9.0,'
'"Illuminance3":1.2}}}'
),
),
(
{
"sensor.tasmota_analog_temperature1": {
"state": "1.2",
"attributes": {
"device_class": "temperature",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
"unit_of_measurement": "°C",
},
},
"sensor.tasmota_analog_temperature2": {
"state": "3.4",
"attributes": {
"device_class": "temperature",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
"unit_of_measurement": "°C",
},
},
"sensor.tasmota_analog_illuminance3": {
"state": "5.6",
"attributes": {
"device_class": "illuminance",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
"unit_of_measurement": "lx",
},
},
},
{
"sensor.tasmota_analog_temperature1": {"state": "7.8"},
"sensor.tasmota_analog_temperature2": {"state": "9.0"},
"sensor.tasmota_analog_illuminance3": {"state": "1.2"},
},
),
),
(
NUMBERED_SENSOR_CONFIG_2,
[
"sensor.tasmota_analog_ctenergy1_energy",
"sensor.tasmota_analog_ctenergy1_power",
"sensor.tasmota_analog_ctenergy1_voltage",
"sensor.tasmota_analog_ctenergy1_current",
],
(
(
'{"ANALOG":{"CTEnergy1":'
'{"Energy":0.5,"Power":2300,"Voltage":230,"Current":10}}}'
),
(
'{"StatusSNS":{"ANALOG":{"CTEnergy1":'
'{"Energy":1.0,"Power":1150,"Voltage":230,"Current":5}}}}'
),
),
(
{
"sensor.tasmota_analog_ctenergy1_energy": {
"state": "0.5",
"attributes": {
"device_class": "energy",
ATTR_STATE_CLASS: SensorStateClass.TOTAL,
"unit_of_measurement": "kWh",
},
},
"sensor.tasmota_analog_ctenergy1_power": {
"state": "2300",
"attributes": {
"device_class": "power",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
"unit_of_measurement": "W",
},
},
"sensor.tasmota_analog_ctenergy1_voltage": {
"state": "230",
"attributes": {
"device_class": "voltage",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
"unit_of_measurement": "V",
},
},
"sensor.tasmota_analog_ctenergy1_current": {
"state": "10",
"attributes": {
"device_class": "current",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
"unit_of_measurement": "A",
},
},
},
{
"sensor.tasmota_analog_ctenergy1_energy": {"state": "1.0"},
"sensor.tasmota_analog_ctenergy1_power": {"state": "1150"},
"sensor.tasmota_analog_ctenergy1_voltage": {"state": "230"},
"sensor.tasmota_analog_ctenergy1_current": {"state": "5"},
},
),
),
],
)
async def test_controlling_state_via_mqtt(
Expand Down Expand Up @@ -409,6 +542,87 @@ async def test_controlling_state_via_mqtt(
assert state.attributes.get(attribute) == expected


@pytest.mark.parametrize(
("sensor_config", "entity_ids", "states"),
[
(
# The AS33935 energy sensor is not reporting energy in W
{"sn": {"Time": "2020-09-25T12:47:15", "AS3935": {"Energy": None}}},
["sensor.tasmota_as3935_energy"],
{
"sensor.tasmota_as3935_energy": {
"device_class": None,
"state_class": None,
"unit_of_measurement": None,
},
},
),
(
# The AS33935 energy sensor is not reporting energy in W
{"sn": {"Time": "2020-09-25T12:47:15", "LD2410": {"Energy": None}}},
["sensor.tasmota_ld2410_energy"],
{
"sensor.tasmota_ld2410_energy": {
"device_class": None,
"state_class": None,
"unit_of_measurement": None,
},
},
),
(
# Check other energy sensors work
{"sn": {"Time": "2020-09-25T12:47:15", "Other": {"Energy": None}}},
["sensor.tasmota_other_energy"],
{
"sensor.tasmota_other_energy": {
"device_class": "energy",
"state_class": "total",
"unit_of_measurement": "kWh",
},
},
),
],
)
async def test_quantity_override(
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,
setup_tasmota,
sensor_config,
entity_ids,
states,
) -> None:
"""Test quantity override for certain sensors."""
entity_reg = er.async_get(hass)
config = copy.deepcopy(DEFAULT_CONFIG)
sensor_config = copy.deepcopy(sensor_config)
mac = config["mac"]

async_fire_mqtt_message(
hass,
f"{DEFAULT_PREFIX}/{mac}/config",
json.dumps(config),
)
await hass.async_block_till_done()
async_fire_mqtt_message(
hass,
f"{DEFAULT_PREFIX}/{mac}/sensors",
json.dumps(sensor_config),
)
await hass.async_block_till_done()

for entity_id in entity_ids:
state = hass.states.get(entity_id)
assert state.state == "unavailable"
expected_state = states[entity_id]
for attribute, expected in expected_state.get("attributes", {}).items():
assert state.attributes.get(attribute) == expected

entry = entity_reg.async_get(entity_id)
assert entry.disabled is False
assert entry.disabled_by is None
assert entry.entity_category is None


async def test_bad_indexed_sensor_state_via_mqtt(
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
) -> None:
Expand Down

0 comments on commit 5bcb4f0

Please sign in to comment.