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
a3ca3e87
Commit
a3ca3e87
authored
8 years ago
by
Open Home Automation
Committed by
Johann Kellerman
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Added support for serial particulate matters sensors - serial_pm (#2571)
parent
d1107a9c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.coveragerc
+1
-0
1 addition, 0 deletions
.coveragerc
homeassistant/components/sensor/serial_pm.py
+94
-0
94 additions, 0 deletions
homeassistant/components/sensor/serial_pm.py
requirements_all.txt
+3
-0
3 additions, 0 deletions
requirements_all.txt
with
98 additions
and
0 deletions
.coveragerc
+
1
−
0
View file @
a3ca3e87
...
...
@@ -206,6 +206,7 @@ omit =
homeassistant/components/sensor/onewire.py
homeassistant/components/sensor/openweathermap.py
homeassistant/components/sensor/openexchangerates.py
homeassistant/components/sensor/serial_pm.py
homeassistant/components/sensor/plex.py
homeassistant/components/sensor/rest.py
homeassistant/components/sensor/sabnzbd.py
...
...
This diff is collapsed.
Click to expand it.
homeassistant/components/sensor/serial_pm.py
0 → 100644
+
94
−
0
View file @
a3ca3e87
"""
Support for particulate matter sensors connected to a serial port.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.particulate_matter/
"""
import
logging
import
voluptuous
as
vol
from
homeassistant.const
import
CONF_NAME
,
CONF_PLATFORM
from
homeassistant.helpers.entity
import
Entity
import
homeassistant.helpers.config_validation
as
cv
from
homeassistant.components.sensor
import
PLATFORM_SCHEMA
REQUIREMENTS
=
[
'
pmsensor==0.2
'
]
_LOGGER
=
logging
.
getLogger
(
__name__
)
CONF_SERIAL_DEVICE
=
"
serial_device
"
CONF_BRAND
=
"
brand
"
PLATFORM_SCHEMA
=
PLATFORM_SCHEMA
.
extend
({
vol
.
Required
(
CONF_PLATFORM
):
'
serial_pm
'
,
vol
.
Optional
(
CONF_NAME
,
default
=
""
):
cv
.
string
,
vol
.
Required
(
CONF_SERIAL_DEVICE
):
cv
.
string
,
vol
.
Required
(
CONF_BRAND
):
cv
.
string
,
})
def
setup_platform
(
hass
,
config
,
add_devices
,
discovery_info
=
None
):
"""
Setup the available PM sensors.
"""
from
pmsensor
import
serial_data_collector
as
pm
try
:
coll
=
pm
.
PMDataCollector
(
config
.
get
(
CONF_SERIAL_DEVICE
),
pm
.
SUPPORTED_SENSORS
[
config
.
get
(
CONF_BRAND
)])
except
KeyError
:
_LOGGER
.
error
(
"
Brand %s not supported
\n
supported brands: %s
"
,
config
.
get
(
CONF_BRAND
),
pm
.
SUPPORTED_SENSORS
.
keys
())
return
except
OSError
as
err
:
_LOGGER
.
error
(
"
Could not open serial connection to %s (%s)
"
,
config
.
get
(
CONF_SERIAL_DEVICE
),
err
)
return
dev
=
[]
for
pmname
in
coll
.
supported_values
():
if
config
.
get
(
"
name
"
)
!=
""
:
name
=
"
{} PM{}
"
.
format
(
config
.
get
(
"
name
"
),
pmname
)
else
:
name
=
"
PM{}
"
.
format
(
pmname
)
dev
.
append
(
ParticulateMatterSensor
(
coll
,
name
,
pmname
))
add_devices
(
dev
)
class
ParticulateMatterSensor
(
Entity
):
"""
Representation of an Particulate matter sensor.
"""
def
__init__
(
self
,
pmDataCollector
,
name
,
pmname
):
"""
Initialize a new PM sensor.
"""
self
.
_name
=
name
self
.
_pmname
=
pmname
self
.
_state
=
None
self
.
_collector
=
pmDataCollector
@property
def
name
(
self
):
"""
Return the name of the sensor.
"""
return
self
.
_name
@property
def
state
(
self
):
"""
Return the state of the sensor.
"""
return
self
.
_state
@property
def
unit_of_measurement
(
self
):
"""
Return the unit of measurement of this entity, if any.
"""
return
"
µg/m³
"
def
update
(
self
):
"""
Read from sensor and update the state.
"""
_LOGGER
.
debug
(
"
Reading data from PM sensor
"
)
try
:
self
.
_state
=
self
.
_collector
.
read_data
()[
self
.
_pmname
]
except
KeyError
:
_LOGGER
.
error
(
"
Could not read PM%s value
"
,
self
.
_pmname
)
def
should_poll
(
self
):
"""
Sensor needs polling.
"""
return
True
This diff is collapsed.
Click to expand it.
requirements_all.txt
+
3
−
0
View file @
a3ca3e87
...
...
@@ -230,6 +230,9 @@ phue==0.8
# homeassistant.components.sensor.plex
plexapi==1.1.0
# homeassistant.components.sensor.serial_pm
pmsensor==0.2
# homeassistant.components.thermostat.proliphix
proliphix==0.2.0
...
...
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