Skip to content

Commit

Permalink
remove check for null string (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniszewski committed Jul 16, 2018
1 parent a1096a6 commit 2596e69
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
16 changes: 3 additions & 13 deletions synse/scheme/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,9 @@ def format_readings(self):
if field is not None:
value = getattr(reading, field)

# FIXME (etd) is this block still relevent with the grpc changes? I don't think it is.
# Handle cases where no data was read. Currently, we consider the reading
# to have no data if:
# - the ReadResponse value comes back as an empty string (e.g. "")
# - the ReadResponse value comes back as the string "null".
if value in ('', 'null'):
logger.info(_('Reading value for {} came back as empty/null').format(rt))
value = None

else:
# Set the specified precision
if precision and isinstance(value, float):
value = round(value, precision)
# Set the specified precision, if specified
if precision and isinstance(value, float):
value = round(value, precision)

formatted.append({
'value': value,
Expand Down
31 changes: 30 additions & 1 deletion tests/unit/scheme/test_read_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_read_scheme():
}


def test_read_scheme_empty_value():
def test_read_scheme_empty_string_value():
"""Test that the read scheme matches the expected when the read value
is an empty string.
"""
Expand All @@ -80,6 +80,35 @@ def test_read_scheme_empty_value():

response_scheme = ReadResponse(dev, [reading])

assert response_scheme.data == {
'kind': 'thermistor',
'data': [
{
'info': '',
'type': 'temperature',
'value': '', # an empty string is a valid value
'timestamp': 'november',
'unit': {
'name': 'celsius',
'symbol': 'C'
}
}
]
}


def test_read_scheme_null_value():
"""Test that the read scheme matches the expected when there is no read value.
"""
dev = make_device_response()

reading = api.Reading(
timestamp='november',
type='temperature',
)

response_scheme = ReadResponse(dev, [reading])

assert response_scheme.data == {
'kind': 'thermistor',
'data': [
Expand Down

0 comments on commit 2596e69

Please sign in to comment.