Move imports to top for random (#29473)

This commit is contained in:
springstan 2019-12-05 06:13:05 +01:00 committed by Paulus Schoutsen
parent d9661b408b
commit c02d551cd5
2 changed files with 6 additions and 6 deletions

View file

@ -1,15 +1,16 @@
"""Support for showing random states.""" """Support for showing random states."""
import logging import logging
from random import getrandbits
import voluptuous as vol import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
BinarySensorDevice,
PLATFORM_SCHEMA,
DEVICE_CLASSES_SCHEMA, DEVICE_CLASSES_SCHEMA,
PLATFORM_SCHEMA,
BinarySensorDevice,
) )
from homeassistant.const import CONF_NAME, CONF_DEVICE_CLASS from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -57,6 +58,5 @@ class RandomSensor(BinarySensorDevice):
async def async_update(self): async def async_update(self):
"""Get new state and update the sensor's state.""" """Get new state and update the sensor's state."""
from random import getrandbits
self._state = bool(getrandbits(1)) self._state = bool(getrandbits(1))

View file

@ -1,5 +1,6 @@
"""Support for showing random numbers.""" """Support for showing random numbers."""
import logging import logging
from random import randrange
import voluptuous as vol import voluptuous as vol
@ -82,6 +83,5 @@ class RandomSensor(Entity):
async def async_update(self): async def async_update(self):
"""Get a new number and updates the states.""" """Get a new number and updates the states."""
from random import randrange
self._state = randrange(self._minimum, self._maximum + 1) self._state = randrange(self._minimum, self._maximum + 1)