mirror of
https://github.com/home-assistant/core.git
synced 2025-05-19 13:29:17 +00:00
Merge pull request #14831 from home-assistant/sim-sensor
Limit sensor.simulated to 3 decimals (fixes #14773)
This commit is contained in:
commit
4bccb0d2a1
@ -100,7 +100,7 @@ class SimulatedSensor(Entity):
|
||||
else:
|
||||
periodic = amp * (math.sin((2*math.pi*time_delta/period) + phase))
|
||||
noise = self._random.gauss(mu=0, sigma=fwhm)
|
||||
return mean + periodic + noise
|
||||
return round(mean + periodic + noise, 3)
|
||||
|
||||
async def async_update(self):
|
||||
"""Update the sensor."""
|
||||
|
@ -1,13 +1,14 @@
|
||||
"""The tests for the simulated sensor."""
|
||||
import unittest
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
from homeassistant.components.sensor.simulated import (
|
||||
CONF_UNIT, CONF_AMP, CONF_MEAN, CONF_PERIOD, CONF_PHASE, CONF_FWHM,
|
||||
CONF_SEED, DEFAULT_NAME, DEFAULT_AMP, DEFAULT_MEAN,
|
||||
DEFAULT_PHASE, DEFAULT_FWHM, DEFAULT_SEED)
|
||||
CONF_AMP, CONF_FWHM, CONF_MEAN, CONF_PERIOD, CONF_PHASE, CONF_SEED,
|
||||
CONF_UNIT, DEFAULT_AMP, DEFAULT_FWHM, DEFAULT_MEAN, DEFAULT_NAME,
|
||||
DEFAULT_PHASE, DEFAULT_SEED)
|
||||
from homeassistant.const import CONF_FRIENDLY_NAME
|
||||
from homeassistant.setup import setup_component
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
class TestSimulatedSensor(unittest.TestCase):
|
||||
@ -27,24 +28,17 @@ class TestSimulatedSensor(unittest.TestCase):
|
||||
'sensor': {
|
||||
'platform': 'simulated'}
|
||||
}
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, 'sensor', config))
|
||||
self.assertTrue(setup_component(self.hass, 'sensor', config))
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert len(self.hass.states.entity_ids()) == 1
|
||||
state = self.hass.states.get('sensor.simulated')
|
||||
assert state.attributes.get(
|
||||
CONF_FRIENDLY_NAME) == DEFAULT_NAME
|
||||
assert state.attributes.get(
|
||||
CONF_AMP) == DEFAULT_AMP
|
||||
assert state.attributes.get(
|
||||
CONF_UNIT) is None
|
||||
assert state.attributes.get(
|
||||
CONF_MEAN) == DEFAULT_MEAN
|
||||
assert state.attributes.get(
|
||||
CONF_PERIOD) == 60.0
|
||||
assert state.attributes.get(
|
||||
CONF_PHASE) == DEFAULT_PHASE
|
||||
assert state.attributes.get(
|
||||
CONF_FWHM) == DEFAULT_FWHM
|
||||
assert state.attributes.get(
|
||||
CONF_SEED) == DEFAULT_SEED
|
||||
|
||||
assert state.attributes.get(CONF_FRIENDLY_NAME) == DEFAULT_NAME
|
||||
assert state.attributes.get(CONF_AMP) == DEFAULT_AMP
|
||||
assert state.attributes.get(CONF_UNIT) is None
|
||||
assert state.attributes.get(CONF_MEAN) == DEFAULT_MEAN
|
||||
assert state.attributes.get(CONF_PERIOD) == 60.0
|
||||
assert state.attributes.get(CONF_PHASE) == DEFAULT_PHASE
|
||||
assert state.attributes.get(CONF_FWHM) == DEFAULT_FWHM
|
||||
assert state.attributes.get(CONF_SEED) == DEFAULT_SEED
|
||||
|
Loading…
x
Reference in New Issue
Block a user