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
14d1494c
Commit
14d1494c
authored
8 years ago
by
Matt N
Committed by
Fabian Affolter
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
systemmonitor: Support monitoring removable network interfaces (#4462)
parent
f1d11e77
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/sensor/systemmonitor.py
+32
-15
32 additions, 15 deletions
homeassistant/components/sensor/systemmonitor.py
with
32 additions
and
15 deletions
homeassistant/components/sensor/systemmonitor.py
+
32
−
15
View file @
14d1494c
...
@@ -10,7 +10,7 @@ import voluptuous as vol
...
@@ -10,7 +10,7 @@ import voluptuous as vol
from
homeassistant.components.sensor
import
PLATFORM_SCHEMA
from
homeassistant.components.sensor
import
PLATFORM_SCHEMA
from
homeassistant.const
import
(
from
homeassistant.const
import
(
CONF_RESOURCES
,
STATE_OFF
,
STATE_ON
,
CONF_TYPE
)
CONF_RESOURCES
,
STATE_OFF
,
STATE_ON
,
STATE_UNKNOWN
,
CONF_TYPE
)
from
homeassistant.helpers.entity
import
Entity
from
homeassistant.helpers.entity
import
Entity
import
homeassistant.helpers.config_validation
as
cv
import
homeassistant.helpers.config_validation
as
cv
import
homeassistant.util.dt
as
dt_util
import
homeassistant.util.dt
as
dt_util
...
@@ -49,6 +49,18 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
...
@@ -49,6 +49,18 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})])
})])
})
})
IO_COUNTER
=
{
'
network_out
'
:
0
,
'
network_in
'
:
1
,
'
packets_out
'
:
2
,
'
packets_in
'
:
3
,
}
IF_ADDRS
=
{
'
ipv4_address
'
:
0
,
'
ipv6_address
'
:
1
,
}
# pylint: disable=unused-argument
# pylint: disable=unused-argument
def
setup_platform
(
hass
,
config
,
add_devices
,
discovery_info
=
None
):
def
setup_platform
(
hass
,
config
,
add_devices
,
discovery_info
=
None
):
...
@@ -126,20 +138,25 @@ class SystemMonitorSensor(Entity):
...
@@ -126,20 +138,25 @@ class SystemMonitorSensor(Entity):
self
.
_state
=
STATE_ON
self
.
_state
=
STATE_ON
else
:
else
:
self
.
_state
=
STATE_OFF
self
.
_state
=
STATE_OFF
elif
self
.
type
==
'
network_out
'
:
elif
self
.
type
==
'
network_out
'
or
self
.
type
==
'
network_in
'
:
self
.
_state
=
round
(
psutil
.
net_io_counters
(
pernic
=
True
)
counters
=
psutil
.
net_io_counters
(
pernic
=
True
)
[
self
.
argument
][
0
]
/
1024
**
2
,
1
)
if
self
.
argument
in
counters
:
elif
self
.
type
==
'
network_in
'
:
counter
=
counters
[
self
.
argument
][
IO_COUNTER
[
self
.
type
]]
self
.
_state
=
round
(
psutil
.
net_io_counters
(
pernic
=
True
)
self
.
_state
=
round
(
counter
/
1024
**
2
,
1
)
[
self
.
argument
][
1
]
/
1024
**
2
,
1
)
else
:
elif
self
.
type
==
'
packets_out
'
:
self
.
_state
=
STATE_UNKNOWN
self
.
_state
=
psutil
.
net_io_counters
(
pernic
=
True
)[
self
.
argument
][
2
]
elif
self
.
type
==
'
packets_out
'
or
self
.
type
==
'
packets_in
'
:
elif
self
.
type
==
'
packets_in
'
:
counters
=
psutil
.
net_io_counters
(
pernic
=
True
)
self
.
_state
=
psutil
.
net_io_counters
(
pernic
=
True
)[
self
.
argument
][
3
]
if
self
.
argument
in
counters
:
elif
self
.
type
==
'
ipv4_address
'
:
self
.
_state
=
counters
[
self
.
argument
][
IO_COUNTER
[
self
.
type
]]
self
.
_state
=
psutil
.
net_if_addrs
()[
self
.
argument
][
0
][
1
]
else
:
elif
self
.
type
==
'
ipv6_address
'
:
self
.
_state
=
STATE_UNKNOWN
self
.
_state
=
psutil
.
net_if_addrs
()[
self
.
argument
][
1
][
1
]
elif
self
.
type
==
'
ipv4_address
'
or
self
.
type
==
'
ipv6_address
'
:
addresses
=
psutil
.
net_if_addrs
()
if
self
.
argument
in
addresses
:
self
.
_state
=
addresses
[
self
.
argument
][
IF_ADDRS
[
self
.
type
]][
1
]
else
:
self
.
_state
=
STATE_UNKNOWN
elif
self
.
type
==
'
last_boot
'
:
elif
self
.
type
==
'
last_boot
'
:
self
.
_state
=
dt_util
.
as_local
(
self
.
_state
=
dt_util
.
as_local
(
dt_util
.
utc_from_timestamp
(
psutil
.
boot_time
())
dt_util
.
utc_from_timestamp
(
psutil
.
boot_time
())
...
...
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