diff --git a/src/utils/stringUtils.ts b/src/utils/stringUtils.ts index d3d50d9..b6ed6dd 100644 --- a/src/utils/stringUtils.ts +++ b/src/utils/stringUtils.ts @@ -8,7 +8,7 @@ import { CLIENT_ERROR } from '../errors'; */ export function valuesToStringList(values: ItemStatusResponse): string[] { try { - return (values['sumstate']['value'] as string).slice(0, -1).split(';'); + return values.sumstate.value.slice(0, -1).split(';'); } catch (e) { throw new Error(CLIENT_ERROR.CANNOT_PARSE_STATUS); } diff --git a/test/utils/stringUtils.test.ts b/test/utils/stringUtils.test.ts index dd65175..c9844ee 100644 --- a/test/utils/stringUtils.test.ts +++ b/test/utils/stringUtils.test.ts @@ -1,3 +1,4 @@ +import { ItemStatusResponse, SystemStatusResponse } from '../../src/client'; import { CLIENT_ERROR } from '../../src/errors'; import { systemFilteredByGroup, @@ -6,15 +7,23 @@ import { } from '../../src/utils/stringUtils'; test('valuesToStringList', () => { - expect(valuesToStringList(JSON.parse('{"sumstate":{"value":"0;0;3;kW;10.001;"}}'), null)).toEqual( - ['0', '0', '3', 'kW', '10.001'] - ); - expect( - valuesToStringList(JSON.parse('{"item0":{"sumstate":{"value":"0;0;3;C°;199.999;"}}}'), 'item0') - ).toEqual(['0', '0', '3', 'C°', '199.999']); + expect(valuesToStringList(JSON.parse('{"sumstate":{"value":"0;0;3;kW;10.001;"}}'))).toEqual([ + '0', + '0', + '3', + 'kW', + '10.001', + ]); + expect(valuesToStringList({ sumstate: { value: '0;0;3;C°;199.999;' } })).toEqual([ + '0', + '0', + '3', + 'C°', + '199.999', + ]); expect(() => { - valuesToStringList(JSON.parse('{"item0":{"sumstate":{"value":"0;0;0;0;0;"}}}'), 'item1'); + valuesToStringList(JSON.parse('{}')); }).toThrow(CLIENT_ERROR.CANNOT_PARSE_STATUS); });