Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
bfb5daa3
Unverified
Commit
bfb5daa3
authored
2 years ago
by
gjong
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add phase information to YouLess (#89255)
parent
38f3b9f1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
homeassistant/components/youless/sensor.py
+98
-1
98 additions, 1 deletion
homeassistant/components/youless/sensor.py
with
98 additions
and
1 deletion
homeassistant/components/youless/sensor.py
+
98
−
1
View file @
bfb5daa3
...
@@ -10,7 +10,14 @@ from homeassistant.components.sensor import (
...
@@ -10,7 +10,14 @@ from homeassistant.components.sensor import (
SensorStateClass
,
SensorStateClass
,
)
)
from
homeassistant.config_entries
import
ConfigEntry
from
homeassistant.config_entries
import
ConfigEntry
from
homeassistant.const
import
CONF_DEVICE
,
UnitOfEnergy
,
UnitOfPower
,
UnitOfVolume
from
homeassistant.const
import
(
CONF_DEVICE
,
UnitOfElectricCurrent
,
UnitOfElectricPotential
,
UnitOfEnergy
,
UnitOfPower
,
UnitOfVolume
,
)
from
homeassistant.core
import
HomeAssistant
from
homeassistant.core
import
HomeAssistant
from
homeassistant.helpers.entity
import
DeviceInfo
from
homeassistant.helpers.entity
import
DeviceInfo
from
homeassistant.helpers.entity_platform
import
AddEntitiesCallback
from
homeassistant.helpers.entity_platform
import
AddEntitiesCallback
...
@@ -47,6 +54,15 @@ async def async_setup_entry(
...
@@ -47,6 +54,15 @@ async def async_setup_entry(
DeliveryMeterSensor
(
coordinator
,
device
,
"
high
"
),
DeliveryMeterSensor
(
coordinator
,
device
,
"
high
"
),
ExtraMeterSensor
(
coordinator
,
device
,
"
total
"
),
ExtraMeterSensor
(
coordinator
,
device
,
"
total
"
),
ExtraMeterPowerSensor
(
coordinator
,
device
,
"
usage
"
),
ExtraMeterPowerSensor
(
coordinator
,
device
,
"
usage
"
),
PhasePowerSensor
(
coordinator
,
device
,
1
),
PhaseVoltageSensor
(
coordinator
,
device
,
1
),
PhaseCurrentSensor
(
coordinator
,
device
,
1
),
PhasePowerSensor
(
coordinator
,
device
,
2
),
PhaseVoltageSensor
(
coordinator
,
device
,
2
),
PhaseCurrentSensor
(
coordinator
,
device
,
2
),
PhasePowerSensor
(
coordinator
,
device
,
3
),
PhaseVoltageSensor
(
coordinator
,
device
,
3
),
PhaseCurrentSensor
(
coordinator
,
device
,
3
),
]
]
)
)
...
@@ -193,6 +209,87 @@ class EnergyMeterSensor(YoulessBaseSensor):
...
@@ -193,6 +209,87 @@ class EnergyMeterSensor(YoulessBaseSensor):
return
getattr
(
self
.
coordinator
.
data
.
power_meter
,
f
"
_
{
self
.
_type
}
"
,
None
)
return
getattr
(
self
.
coordinator
.
data
.
power_meter
,
f
"
_
{
self
.
_type
}
"
,
None
)
class
PhasePowerSensor
(
YoulessBaseSensor
):
"""
The current power usage of a single phase.
"""
_attr_native_unit_of_measurement
=
UnitOfPower
.
WATT
_attr_device_class
=
SensorDeviceClass
.
POWER
_attr_state_class
=
SensorStateClass
.
MEASUREMENT
def
__init__
(
self
,
coordinator
:
DataUpdateCoordinator
[
YoulessAPI
],
device
:
str
,
phase
:
int
)
->
None
:
"""
Initialize the power phase sensor.
"""
super
().
__init__
(
coordinator
,
device
,
"
power
"
,
"
Energy usage
"
,
f
"
phase_
{
phase
}
_power
"
)
self
.
_attr_name
=
f
"
Phase
{
phase
}
power
"
self
.
_phase
=
phase
@property
def
get_sensor
(
self
)
->
YoulessSensor
|
None
:
"""
Get the sensor value from the coordinator.
"""
phase_sensor
=
getattr
(
self
.
coordinator
.
data
,
f
"
phase
{
self
.
_phase
}
"
,
None
)
if
phase_sensor
is
None
:
return
None
return
phase_sensor
.
power
class
PhaseVoltageSensor
(
YoulessBaseSensor
):
"""
The current voltage of a single phase.
"""
_attr_native_unit_of_measurement
=
UnitOfElectricPotential
.
VOLT
_attr_device_class
=
SensorDeviceClass
.
VOLTAGE
_attr_state_class
=
SensorStateClass
.
MEASUREMENT
def
__init__
(
self
,
coordinator
:
DataUpdateCoordinator
[
YoulessAPI
],
device
:
str
,
phase
:
int
)
->
None
:
"""
Initialize the voltage phase sensor.
"""
super
().
__init__
(
coordinator
,
device
,
"
power
"
,
"
Energy usage
"
,
f
"
phase_
{
phase
}
_voltage
"
)
self
.
_attr_name
=
f
"
Phase
{
phase
}
voltage
"
self
.
_phase
=
phase
@property
def
get_sensor
(
self
)
->
YoulessSensor
|
None
:
"""
Get the sensor value from the coordinator for phase voltage.
"""
phase_sensor
=
getattr
(
self
.
coordinator
.
data
,
f
"
phase
{
self
.
_phase
}
"
,
None
)
if
phase_sensor
is
None
:
return
None
return
phase_sensor
.
voltage
class
PhaseCurrentSensor
(
YoulessBaseSensor
):
"""
The current current of a single phase.
"""
_attr_native_unit_of_measurement
=
UnitOfElectricCurrent
.
AMPERE
_attr_device_class
=
SensorDeviceClass
.
CURRENT
_attr_state_class
=
SensorStateClass
.
MEASUREMENT
def
__init__
(
self
,
coordinator
:
DataUpdateCoordinator
[
YoulessAPI
],
device
:
str
,
phase
:
int
)
->
None
:
"""
Initialize the current phase sensor.
"""
super
().
__init__
(
coordinator
,
device
,
"
power
"
,
"
Energy usage
"
,
f
"
phase_
{
phase
}
_current
"
)
self
.
_attr_name
=
f
"
Phase
{
phase
}
current
"
self
.
_phase
=
phase
@property
def
get_sensor
(
self
)
->
YoulessSensor
|
None
:
"""
Get the sensor value from the coordinator for phase current.
"""
phase_sensor
=
getattr
(
self
.
coordinator
.
data
,
f
"
phase
{
self
.
_phase
}
"
,
None
)
if
phase_sensor
is
None
:
return
None
return
phase_sensor
.
current
class
ExtraMeterSensor
(
YoulessBaseSensor
):
class
ExtraMeterSensor
(
YoulessBaseSensor
):
"""
The Youless extra meter value sensor (s0).
"""
"""
The Youless extra meter value sensor (s0).
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment